regex match 0);
I have the following regular expression:
SOMETHING(.*?),(1|0)\\);
It needs to match SOMETHING then anything, then a comma, then 1 or 0 followed by ); but for some reason t开发者_开发百科he last bracket isn't being matched, an example string:
SOMETHINGdfsdfdsfd dsffdsdf dfsfds FEHEF777a ,0);
the bold part is the ending. Am I escaping the ) wrong? \ should work...
example php where $o is my string
preg_match_all('%INSERT INTO (.*?),(1|0)\);%sm', $o, $matches);
Your original post doesn't show you are escaping it. You need:
SOMETHING(.*?),(1|0)\);
If you have that, what is the language running the regular expression, e.g. Java, PHP, Perl?
UPDATE
There are some things to consider. You are using a non-greedy expression in your first capture. In combination with your modifiers (multiline and dot all) this could be conflicting. Furthermore, based on your input you may need to escape the first set of parenthesis.
Regular Expressions are very powerful, but only as powerful as their creators. That is to say they often fail unless you know exactly what you are wanting to match.
It does work here, did you maybe mean to get the ending );
in there? If so:
SOMETHING(.*?),((?:1|0)\);)
Otherwise: what language are we talking about? Do you need to double or triple the \
? (\\
/ \\\
can be possible in some implementations).
Edit: OK, php
$php -r 'var_dump(preg_match_all("/SOMETHING(.*?),(1|0)\);/","SOMETHINGdfsdfdsfd dsffdsdf dfsfds FEHEF777a ,0);",$matches),$matches);'
int(1)
array(3) {
[0]=>
array(1) {
[0]=>
string(49) "SOMETHINGdfsdfdsfd dsffdsdf dfsfds FEHEF777a ,0);"
}
[1]=>
array(1) {
[0]=>
string(36) "dfsdfdsfd dsffdsdf dfsfds FEHEF777a "
}
[2]=>
array(1) {
[0]=>
string(1) "0"
}
}
Perfect match.
精彩评论