Regular expression without spaces or special characters [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
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

Related

Complex Regex Pattern Combining Numbers with Letters [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
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);

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

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);

Categories