IAddBugsToCodebases
IAddBugsToCodebases

Reputation: 525

How to join two regex?

I have this two regex

/^[^+\x2f\s\x5c ]+$/ - don't accept slashes, + or white spaces

/(?!^\d+$)^.+$/ - Don't be only numbers

I would like to join them in one. How can I join them?

Upvotes: 1

Views: 82

Answers (3)

MonkeyZeus
MonkeyZeus

Reputation: 20737

I would personally go for something like this over regex because it's more readable:

if (
    !ctype_digit($string) &&
    strpos($string, '\\') === FALSE &&
    strpos($string, '/') === FALSE &&
    strpos($string, '+') === FALSE &&
    !preg_match('white spaces regex goes here', $string)
) {
    // Good to go
}
else {
    // Error
}

Upvotes: 1

Kenny Lau
Kenny Lau

Reputation: 465

/^(?!^\d+$)[^+\x2f\s\x5c ]+$/

Negative look-ahead followed by the matching.

Upvotes: 2

anubhava
anubhava

Reputation: 784948

You can join them as:

^(?!^\d+$)[^+\x2f\s\x5c ]+$

RegEx Demo

Upvotes: 2

Related Questions