|
I'm confused about the array returned by a regex match when using both /g (to get multiple matches) and parentheses (to get backreferences). It's not clear to me how to get the backreferences because the subscript of the match array seems to refer to ...
Started by brad on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
Alert(match[1]); }
You should use non.
Var str = "@abc @bcd @cde", re = /@([a-z]+)/g, match; while (match = re.exec(str)) { // match[1] contains text matched by first group, match[2] - second, etc.
|
|
I have a string which has several html comments in it. I need to count the unique matches of an expression.
For example, the string might be:
var teststring = "<!--X1-->Hi<!--X1-->there<!--X2-->";
I currently use this to get the matches...
Started by Sailing Judo on
, 6 posts
by 6 people.
Answer Snippets (Read the full thread at stackoverflow):
.*) // // Options: dot matches newline // // Match the regular expression below and capture its match into backreference number 1 «(<!--X\d-->)» // Match the characters “<!--X” literally «<!--X» // Match ....
|
|
Hello
I'm trying to match C style comments form a file, but only if the comment don't start with a certain labels introduced by @
For example from
/* some comment to match */ /* another comment. this should match also */ /*@special shouldn't match*/
Is...
Started by Calin Don on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at stackoverflow):
// ...anything that is not "*/" )* // but match it as often as possible \*/ ....
(?!\*/).
You could start with something like this:
/\*[^@]
But in general, you don't watch to match C-style (?!@) // not followed by "@" (?: // don't capture...
|
Ask your Facebook Friends
|
Consider the following Javascript regular expression matching operation:
"class1 MsoClass2\tmsoclass3\t MSOclass4 msoc5".match(/(^|\s)mso.*?(\s|$)/ig);
I would expect it to return [" MsoClass2\t", "\tmsoclass3\t", " MSOclass4 ", " msoc5"] . Instead it...
Started by Tim Molendijk on
, 6 posts
by 6 people.
Answer Snippets (Read the full thread at stackoverflow):
This is becaue you are using ^ OR \s(whitespace) for first match match():
/mso.*?(\s|$)/ig
Hi,
I am not sure you can use something like (^|\s) and (\s|$) , first to think to understand a regex :....
Doesn't match the initial space.
|
|
I know that it is easy to match anything except a given character using a regular expression.
$text = "ab ac ad"; $text =~ s/[^c]*//g; # Match anything, except c. $text is now "c".
I don't know how to "except" strings instead of characters. How would ...
Started by ssn on
, 7 posts
by 7 people.
Answer Snippets (Read the full thread at stackoverflow):
How would I "....
Use Test::More 0.88; #Match any whole text" if $text !~ /ac/;
or
print "ac not found" unless $text =~ /ac/;
$text =~ s/[^c]*//g; // Match anything is therefore redundant.
You can easily modify this regex for your purpose.
|
|
I am trying to parse url-encoded strings that are made up of key=value pairs separated by either & or & .
The following will only match the first occurrence, breaking apart the keys and values into separate result elements:
var result = mystring.match...
Started by Adam Franco on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at stackoverflow):
Set the g modifier for a global match:
/…/g
You need to use the 'g' switch for a global search
var;)?)([^=]+)=?([^&]*)?/g; var match; while (match = re.exec(url)) { alert(match[1] + " = " + match[2.
|
|
I can't see a reason why the Matcher would return a match on the pattern, but split will return a zero length array on the same regex pattern. It should return something -- in this example I'm looking for a return of 2 separate strings containing "param...
Started by hal10001 on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at stackoverflow):
The pattern can be simplified to:
protected match attempt it finds "param....
Also, you don't even need to capture for this.
Split() doesn't return the match, only what's in between match.
The pattern can match the entire string.
|
|
Let's say I'm matching with a pattern that has subexpressions like this:
Regex myRegex = new Regex("(man|woman|couple) seeking (man|woman|couple|aardvark)"); string myStraightText = "Type is man seeking woman, age is 44"; MatchCollection myStraightMatches...
Started by JCCyC on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
Try this:
myMatch.Groups[0] // "man seeking woman" myMatch.Groups[1] // "man" myMatch.Groups[2] // "woman"
EDIT : To make answer more complete, if you have:
new Regex("(?<seeker>man|woman|couple) seeking (?<target>man|woman|couple)");
you ... .
|
|
I am trying to build a crawler that gets the movie urls from an imdb list. I am able to get all the links on the page into an array and want to select only those ones with "title" in them.
preg_match_all($pattern, "[125] => href=\"/chart/2000s?mode...
Started by Vishwanath on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
When preg_match_all is called?
The error you are getting comes when the pattern provided to preg_match_all (1st argument) is not properly delimited..
|
|
I'm attempting to run preg_match to extract the SRC attribute from the first IMG tag in an article (in this case, stored in $row->introtext).
preg_match('/\< *[img][^\>]*[src] *= *[\"\']{0,1}([^\"\']*)/i', $row->introtext, $matches);
Instead...
Started by KyokoHunter on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at stackoverflow):
Try:
preg_match('/< *img[^>]*src *= *["\']?([^"\']*)/i', $row.
Your expression is incorrect.
|