I would like to know how to get the regular expression of the following text:
XXXXXX[Some Same Text # AAAA-NNNN]XXXXXX
Where:
'X' can vary any text: Alfa, numerical or symbols (The X can have 0 to infinite characters and it is NOT obligatory).
'A' Alfa uppercase text (The Alfa has exactly 4 uppercase letters and it is obligatory).
'N' Numbers (The N have exactly 4 numbers and it is obligatory).
'Some Same text' has exactly the same text always and it is obligatory.
'[,],#,-' will always be there in that same possition and it is obligatory.
I have a preg_match that goes:
*[Some Same Text([A-Z]{4})-([0-9]{4})]*
And it isn't seem to be working.
Thanks and regards!
.
matches any character, and *
means 0..infinity. When using [
and ]
you need to escape them. Try this:
.*\[Some Same Text # ([A-Z]{4})-([0-9]{4})\].*
This should work: '/^.*\[Some Same Text\s#\s[A-Z]{4}-\d{4}\].*$/'
. As Tested:
if(preg_match('/^.*\[Some Same Text\s#\s[A-Z]{4}-\d{4}\].*$/', 'XXXXXX[Some Same Text # AAAA-4444]XXXXXX'))echo 1;