Complex Regex Pattern Combining Numbers with Letters [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
To search for a specific string, which is like UE-42F5070, in a text with preg_match function I am trying to write a regular expression. I am not able to write the regular expression pattern for "UE-##F####", where #'s are numbers, to use with preg_match to find them in the text.
Example of the string;
UE-32F5070
UE-50F8000

You can use this regex:
'/^UE-\d{2}F\d{4}$/'
Recommended Reading on Regex
Details:
^ - Start input
UE - Match literal "UE"
\d{2} - Match 2 digits
F - Match literal "F"
\d{4} - Match 4 digits
$ - End input

A number in regex is [0-9] or \d. Repetitions are {n}. So
UE-[0-9]{2}F[0-9]{4}
Or
UE-\d\dF\d\d\d\d

It looks like UE is a constant, so you can start your regex with that as a literal, the rest should just be:
preg_match('/UE-([0-9]{2}F[0-9]{4})/', $string, $matches);

Related

get numbers after the last occurance of alphabet from string using php regex [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
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.
Closed 8 years ago.
Improve this question
i have sequence of strings in excel file.
example:
1780CAR405108CCC72
1780CAR405108KK89.0
1780CAR405108B7888
I need to get the numbers/floats whatever after the last occurrence of an ALPHABET
like in these examples above, after CCC or KK or B. need assistance asap....
preg_match('#[^a-zA-Z]+$#', $string, $result);
[a-zA-Z]([\d\.]+?)$
lazy match anchored at the end of the string, matches digits and fullstops into a capture group.
Also, since you're using PHP, you can use this if you don't want to deal with capture groups:
(?<=[^\d])[\d\.]+?$
You can match
[^a-zA-Z]+$
[^a-zA-Z] is a negated character class, it stands for "one character, any character but the ones inside the class". $ matches the end of the string.
See demo here.
Using preg_match:
preg_match('/[^a-zA-Z]+$/', "1780CAR405108B72", $match);
print($match);
$matches will contain numbers/float after alphabets.
preg_match('/[^a-zA-Z]+$/', "1780CAR405108B72",$matches);
'/pattern/'==> where slash is the delimiter.

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.

RegEx match making with any character length [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
Hi so I need to write a program where it validates input.
The specifications are " letters, spaces, colon, semi-colon, dash, comma, apostrophe and numeric character (0-9) only - cannot be blank"
I know how to do this when I have an explicit number of characters to use, but in this case it can be any amount of characters, 1-50 and I do not know what to do for regular expression notation in this case of any number of characters. How can I start this?
When you say that the input line cannot be blank I imagine that, while you want to allow spaces, the line itself cannot be spaces only.
Based on that perception I suggest this regex. The negative lookahead, in parentheses, make sure that the line is not all spaces.
^(?!\s+$)[-A-Za-z0-9:;'\s]{1,50}$
You just need the + character if you're trying to match any number of something (but at least one). Here's is an example:
^[A-Za-z :;\-,'\d]+$
To match the whole string:
^[A-Za-z0-9 :;,'-]{1,50}$
To match it as part of a string:
[A-Za-z0-9 :;,'-]{1,50}
There are several options to represent multiplicities in regular expressions:
k? means there is either 0 or 1 k possible, i.e.   or k
k*means there are 0 or more ks possible, e.g.  , k, kk, ...
k+ means there are 1 or more ks possible, e.g. k, kk, ...
k{5} means there are exactly 5 ks, i.e kkkkk
k{3,} means there are at least 3 ks, e.g. kkk, kkkk, ...
k{2,4} means there are either 2, 3 or 4 ks.
For further reading please see the corresponding page of the PHP Documentation.

Build my specific 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 am trying to build a regular expression for a specific problem but I cannot achieve to do it. I have a structure of a string like this 01422756860-8.
As you can see there is a string of length 13. The first 11 characters should be numbers in the interval of [0-9], the next character is a line(minus) and the last character is again a number. There shouldn be any space in between these characters.
Could anyone please help me to do this? I am going to use this regex in php.
I look forward on your answer.
Thank You.
What's the problem?
/^[0-9]{11}-[0-9]$/
Demo
Autopsy:
^ The string must start here
[0-9]{11} Any digit from 0 to 9 repeated exactly 11 times
- A literal dash
[0-9] Any single digit from 0 to 9
$ The string must end here
This regular expression should do it
\d{11}-\d

Regular expression without spaces or special characters [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 am new to regular expressions and I need a regex for php username that matches
no spaces
no special characters
in length 8, max 32
and also a regex for password that matches
alphanumeric have at least one digit and one character
no spaces
Try the following REGEX :
^\S+\w{8,32}\S{1,}
^ means beginning of line
\S means all characters but not a space or a tab
+ mean at least one character
\w means an alphanumeric character including _
{8,32} means at least 8 characters, and max 32
\S still means all characters but not a space or a tab
{1,} means at least 1 item

Categories