match a string without having spaces with regex

regex no spaces or special characters
regex for string without whitespace
regex password validation no spaces
regular expression not allow only spaces
regex whitespace
regex match word no whitespace
regex only letters no spaces
regex match words without space

this is my string I want to get only "GG-00"

$html = "
<td class="P12"> n                Gg-08n            </td>
<li class="P13"> n                GG-00n            </li>
<li class="P122"> n                Gt-90n            </li>
<img class="m43" src="../a.img"></img>
//and more like that//
"
preg_match('/[A-Z]{2}-[0-9]{2}/', $html, $output);

I want to get only GG-00 which in

<li class="P13">

This should do it (assuming it's always two capitals followed by a hyphen and two numbers):

/[A-Z]{2}-[0-9]{2}/

Alphanumeric without space, Match anything enclosed by square brackets. Blocking site with unblocked games � Simple date dd/mm/yyyy � Find Substring within a string that begins and ends� Regex - match a string without leading and trailing spaces. Building an expression that will reject an untrimmed input string. Have a group of white-listed symbols, including whitespace. But it cannot be used at the first or at the last one position.

It all depends what do you want to extract. If you want to extract only that specific "GG-00" you can go with:

$html = '<li class="P12"> n                GG-00n            </li>';
preg_match('/[A-Z]{2}-[0-9]{2}/', $html, $matches);
print_r($matches);

Will output:

Array ( [0] => GG-00 )

If your problem is more complex than this single case you can also think of reading HTML DOM and getting all LI elements

$doc = new DOMDocument();
$doc->loadHTML('<li class="P12"> n                GG-00n            </li>');
$elements = $doc->getElementsByTagName('li');
foreach ($elements as $element) {
    $html = $doc->saveHtml();
    preg_match('/[A-Z]{2}-[0-9]{2}/', $html, $matches);
    print_r($matches);
}

RegexOne - Lesson 9: All this whitespace, The most common forms of whitespace you will use with regular expressions are the In addition, a whitespace special character \s will match any of the specific In the strings below, you'll find that the content of each line is indented by� Regular Expression to Matches Alphanumeric characters without space. https://digitalfortress.tech/tricks/top-15-commonly-used-regex/

You need the following:

/[A-Z].-[0-9]./gm

here is the php:

<?php

$matches = null;
preg_match('/[A-Z].-[0-9]./m', '<li class="P12"> n                GG-00n            </li>', $matches);
print_r($matches);

Learn Regular Expressions - Problem 6: Trimming , replace and a regular expression to extract the content of the lines without the extra whitespace. We have previously seen how to match a full line of text using� Regex - match everything without whitespace. Ask Question - match everything without space. But i need more performance and in benchmark i see that (.*)

This is one of the things you can do;

$string = '<li class="P12"> n                GG-00n            </li>';
$string = explode('<li class="P12"> n                ', $string);
$string = explode('            </li>', $string[1]);
$thecode = $string[0];

With this there can also be different codes...

Matching Whitespace & Non-Whitespace Character, You have a test string . Your task is to match the pattern. Here, denotes whitespace characters, and denotes non-white space characters. Note. This is a regex� Match string not containing string Given a list of strings (words or other characters), only return the strings that do not match. Top Regular Expressions. Match

How can I compare two strings, ignoring any white space or , How can I compare two strings, ignoring any white space or punctuation characters? You can use regular expressions to remove the characters from the strings that John: No, if you 'split' with that expression, you would be left only with� Just enter your string and regular expression and this utility will automatically extract all string fragments that match to the given regex. There are no ads, popups or nonsense, just an awesome regex matcher. Load a string, get regex matches. Created for developers by developers from team Browserling.

Using Regex to get strings with whitespace within them., newArr = regexp(myString, pattern,'match');. I'd like to get the ID called 'HON WI', but with my current pattern, its splitting it� As both the strings has similar characters but in different case. So to match these strings by ignoring case we need to convert both strings to lower case and then match using operator == i.e. if firstStr.lower() == secStr.lower(): print('Both Strings are same')

How to replace white space inside a string in JavaScript, The \s meta character in JavaScript regular expressions matches any whitespace character: spaces, tabs, newlines and Unicode spaces. This regular expression ^\w+(\s\w+)*$ will only allow a single space between words and no leading or trailing spaces. Below is the explanation of the regular expression: ^ Assert position at start of the string \w+ Match any word character [a-zA-Z0-9_] Quantifier: + Between one and unlimited times, as many times as possible, giving back as needed [greedy]

Comments
  • preg_match_all('/GG-00/', .. as good as any considering the information provided
  • It will be changed every time but it will be like that AA-11 or FV-22
  • what's the EXACT pattern? we are not psychic
  • @ss.5 can you please be more specific? From your other comments I understand you have one string with the entire HTML page and you want to extract [A-Z]{2}-[0-9]{2} if it is within a <li class="P12">. Correct me if I'm wrong, but it's certainly not very clear what you want to do exactly. Also, what other characters can appear within the li?
  • very helpful but my strings which is in $html are many, so how to find this class and match [A-Z]{2}-[0-9]{2}? I tried this but not working "$this->match('/<li class="P12"> n([A-Z]{2}-[0-9]{2})<\/li>/ms', $html, 1);"
  • Can you please share more complex example? Can you show me what would you like as input and what as output? I assume: input string, output array of string ("gg-00" etc)?
  • Thank you but I wanted with regex like /[A-Z].-[0-9]./gm