Jump to content

StringRegExp? string left of an algorithm

Recommended Posts

Hi I have a string and I want to get what is right of it. the string looks like this:

('1234,'randomletters');" href="javascript:void(0);">[skip]</A> ... etc

The problem is the string can have 4 numbers or 3 number sin the beginning. and there are different amounts of random letters.

How can i only extract ('1234,'randomletters');

This is what I have so far

or $j = 2 To 50 Step 1

$arrayN [$j] = StringTrimLeft ($arrayNames[$j],95)

$arrayNTwo [$j] = StringTrimRight ($arrayN [$j],730)

MsgBox (1,"channelnames",$arrayNTwo [$j])



Link to post
Share on other sites

I hope this helps.

Local $sString = "('1234,'randomletters');"" href=""javascript:void(0);"">[skip]</A> ... etc"

Local $sSubStr = StringRegExpReplace($sString, "(?is)^(?:.*)(\([""']?\d{3,4}[""']?,[""'][a-z]+[""']\))(.*$)", "$1")

MsgBox(0, "RE", "From:-" & @LF & $sString & @LF & "  is extracted:- " & @LF & $sSubStr)

The Reg Exp Pattern:-
(?is)   <- (?i) & (?s) See StringRegExp function in help file.
^      <- Start matching from the beginning of the test string.
(?:...)  <- Non-capturing group. ( No back-referencing number produced)
.*    <- Match any character including vertical white characters (newlines) until the preceeding RE pattern matches characters in the test string. (inside non-capturing group).
(      <- Open first capture group. From here to matching closing bracket, all that is captured will be designated the first back-reference, $1 or ${1}, or \1.
\(    <- An escaped open bracket will match an actual open bracket character.
[""']?  <- This will match either one or none single or double quote. There are two double quote because the whole RE pattern is enclosed with double quotes.
           The question mark is a repeating character, meaning the previous character may be matched once (number of times) or none (does not have to be present) {0,1}.
\d{3,4} <- Will match any digit (0 to 9), three (3) or four (4) number of times.
[""']?  <- Same as before
,      <- Matches a coma that must be there is this capturing group is to match.
[""']   <- Same as above except without "?". the repeating character. One double or single quote has to be present for the group to match.
[a-z]+  <- Will match any letter (a to z), and because of the previous "(?i)" will also match letters (A to Z), once or many number of times ("+" repeating character like {1,} ).
[""']   <- Same as before.
\)    <- An escaped closing bracket will match an actual close bracket character.
)      <- Closing the first capture group. End of capturing of characters that can be recalled as a group with "$1" ( the first back-reference).
(.*$)   <- This is a second capture group that will match any remaining characters, if any exists, {0,) times, to the end of the string.
           Because of the previous "(?s)", vertical white characters (newlines) will also be matched, if they exist.

The Reg Exp Replacement parameter:-
"$1"    <- This contains all matches that occurred within the first capture group. Note - The second capture group "$2" is not replaced with anything.
Link to post
Share on other sites

StringInStr() also gets you what you want...

Local $sString = "('1234,'randomletters');"" href=""javascript:void(0);"">[skip]</A> ... etc"
$iPos = StringInStr($sString, ';" href')
$sSubStr = StringLeft($sString, $iPos)

MsgBox(0, "", $sSubStr)
Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...