|
I've read how accented characters might sometimes match [a-z] . What I'd like to know is how I could match a specific accented character. Obviously, preg_match('/[ñ]/', 'ñ') does not work.
Started by Nikki Erwin Ramirez on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
Reference.pcre.pattern.modifiers.php
You can take their codes and match them like \xD0 - heximal sequences.
|
|
Hello,
I have some data similar to this:
aaa1|aaa2|ZZZ|aaa3|aaa4|aaa5|ZZZ|aaa6|aaa7
I want to match all "aaa[0-9]" BETWEEN "ZZZ" (not the ones outside).
So I have some PHP code: $string = "aaa1aaa2zzzzaaa3aaa4aaa5zzzzaaa6aaa7"; preg_match_all("/zzzz.*...
Started by Jamie on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
If (preg_match('/zzzz(.*?)zzzz/', $string, $matches)) { preg_match_all('/(aaa\d)/', $matches[1], $newmatches); print_r($newmatches); } else { echo "No match"; }
Check that the string occurs before one = "aaa1aaa2zzzzaaa....
|
|
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.
|
Ask your Facebook Friends
|
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 ....
|
|
If you want to check if something matches a regex, if so, print the first group, you do..
import re match = re.match("(\d+)g", "123g") if match is not None: print match.group(1)
This is completely pedantic, but the intermediate match variable is a bit...
Started by dbr on
, 4 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
It does seem odd that a context manager(self.matches, name) class re2(object): def __init__(self, expr): self.re = re.compile(expr) def match(self "no match"
You can compile....
Like it's going to yield multiple results for each 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...
|
|
Hello all,
I am trying to match a html element but I don't think its matching since $titles is empty - can anyone correct me?
My preg_match:
preg_match_all("~<td align=\"left\" width=\"50%\">[^<]*. <b><a href=\"(.*?)\">[^<]*<...
Started by Abs on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at stackoverflow):
I'd suggest not using a regex to parse.
There's nothing to match title="Wat" in the <a> tag.
|
|
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.
|
|
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 ... .
|