Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I'm not very good at regular expressions. Please help make the expression.
$subject = "action[attribute1=value1,attribute2=values,...]";
// format is ^word[str=str,...]$
I need to match "action", "attributes" and "values". thanks.
First find a match with regex pattern \b(\w+)\[((?:(?<=[,\[])(?:\w+)=(?:[^,\]]+)[,\]]?)+)]
to get action name as Group 1 and parameter list as Group 2.
In next step apply regex pattern (?:^|(?<=,))(\w+)=([^,\]]+)(?=,|$) to Group 2 from above regex
to get a list of attributes and associated values...
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Looking for regex to do the following in php:
Identify if the given string is in the pattern string1_string2_number e.g ph_val_34563, ph_val_296987 etc.
When true, extract the number part.
regex = "^[A-Za-z]+_[A-Za-z]+_(\d+)$"
Assuming that the valid characters for your strings are letters, [A-Za-z]+ says to expect a group of one or more letters. The _ following these character classes says that an _ must follow.
(\d+) says to group, and capture, a set of one or more numbers following the previous expression.
^ says: "begins with"
$ says: "ends with"
You should take a look at a tutorial on regular expressions.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I'm not that good at Regex,
Can you give me a pattern to match any php tags? [<?, <?php]
if you have a nice and simple guide for Regex i'd be happy to have it too :)
I already tried:
'/^(<\?)$/'
But it doesn't really help =/
Thanks!
You will need preg_match_all to match tags, plural. The below will match blocks of PHP and store the code.
preg_match_all( '/<\?php(.+?)\?>/is', $php, $blocks );
print_r( $blocks );
One issue will be if you happen to have the string '?>' in your code not occuring as a PHP closing tag. Would need to know more about your file(s) to advise.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I need to create a regex that will select the data between two characters (& - #).
& foo #
I would like to select foo.
Any ideas? Good explanations are also appreciated.
how about this:
preg_match('~&([^#]*)#~',$content,$match);
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I need to retrieve a list of words, but don't want any words that contain a number or numbers in them.
The idea is very simple, but I'm not even sure how to try. I have one column of words some of which have numbers in them. I only want to retrieve the ones without numbers.
How would I do this in my SQL query?
Thanks
Use a regular expression, either with php's preg_match, or with REGEXP in mysql.
SELECT list_col FROM list_table WHERE list_col NOT REGEXP '[0-9]'
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I want a regex that will help me to get the 4 numbers before the cc.
The RegEx must contain the cc to identify these exact number.
Example:
1600cc
You should use:
/(\d{4})cc\b/
\b ensures that "cc" is at the and of the word.
preg_match('/(\d{4})cc/', $string, $match);
$match[1] will contain the number.