Regular expression needed for "<!-- A-Za-z0-9 -->" [closed] - php

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
Need help with regular expression for <!-- A-Za-z0-9 --> where all the uppercase, smallcase and digits are allowed. Need a regular expression to find this chunk including the comment tags (<!-- -->).

[<!\-\-A-Za-z0-9\-\->]
This is a character class and the order doesn't matter in a character class. What will work however:
<!--\s*[A-Za-z0-9]+\s*-->
If you now want to include spaces inside the comment, you can use:
<!--\s*[A-Za-z0-9 ]+\s*-->
I used the \s* in case there are several white spaces between the <!-- and --> and the part to capture.
Use preg_match_all and if you want to make the regex shorter, you can use the i flag. something like this:
preg_match_all('~<!--\s*[a-z0-9]+\s*-->~i', $page, $matches);

This is all I can think of according to your question
#<!--([A-Za-z0-9]*)-->#

Related

RegEx to find a pattern [closed]

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.

PHP "Kill" all characters from string except A-Z and ";" [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
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
Improve this question
$string='A;B;C;1;2-;D'
how can i remove all characters from this the string above but keep the Letters and the ";"
Try this simple regex:
preg_replace('/[^A-Z;]+/', '', $string);
or
preg_replace('/[^A-Z;]+/i', '', $string);
If you need case insensitive.
You can use:
$repl = preg_replace('/[^a-z;]+/i', '', $str);
^a-z; inside square brackets (character class) means match anything but English letters a-z (range) OR a semi-colon ;
/i is for ignore case to avoid matching uppercase/lowercase english letters.
try this
preg_match('/[^a-z;]/i', $string);

Please decode this regular expression for me [closed]

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 inherited some php code for a webgame that I am trying to modify. I came across this line, and I can't figure out what it is supposed to be doing. Could someone help me out? $notice is just a regular string.
$notice = preg_replace("#([\S]{60})#i", "\\1 ", $notice);
It will find any continuous sequence of 60 non-whitespace characters in $notice, and insert a space after it:
(..) creates a capture group. Because it's the first group it's referred to as \1 in the replacement string. Because the whole pattern is in the group it's not really needed here.
[..] create a character class, but because it contains only one meta-character, it's not really needed here, either.
\S matches any non-whitespace character
{60} is a quantifier; it means 'repeated 60 times'.
This code is equivalent to:
$notice = preg_replace("#\S{60}#i", "\\0 ", $notice);

Replace HTML entities with regular expression [closed]

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 would like a regular expression in PHP to find all HTML entities such as "<br /> <br /> ..etc. " in order to remove them from a long string.
This one removes alpha, decimal and hex HTML entities:
$text = preg_replace('/&(?:[a-z\d]+|#\d+|#x[a-f\d]+);/i', '', $text);
Try using this regex... the [^\s]* one was capturing a whole lot other nonsense...
$text = preg_replace("/&(?:[a-z0-9]{2,8}|#[0-9]{2,3}+);/i", '', $text);
Try using strip_tags function, regex is not necessary here

Assistance with PHP Regex [closed]

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 don't usually use regular expressions, hence my question. I need a regex to match the following:
'{any-string}'.
Any assistance appreciated.
The most simple expression would be:
/{(.*?)}/
If you expect more complex strings (for example, some kind of escape sequence where the { and } characters are allowed within the string) it could be more complex. For instance, with a \ (backslash) escape sequence:
/{((?:\\.|[^}])*)}/
Edit: That's not tested, but the general idea is that the expression will swallow any character following the escape rather than ensuring it isn't the closing brace.
To replace anything in { } with what file_get_contents returns you can do:
$page = file_get_contents('some_file_name or some_url');
$str = '.....{...}....';
$str = preg_replace('/{[^}]*}/',"$page",$str);

Categories