0

I need a regex that will match only strings of this kind

Match these strings:

edo-apple-iphone-5s-i-gold-16

DON'T match these strings:

edo-apple-iphone-5s-i-gold-16-edo-staff-connect-24

The main difference between the 2 strings is either a connect-24 OR handset-24 added to the end of the string

I have written a Regex, but it seems to match both strings:

^edo[a-z1-9\-]*

How do i modify this to not accept if connect-24 OR handset-24 is in the string?

4
  • 1
    Can you post what you've written? Commented Jan 15, 2015 at 2:29
  • 2
    Can you describe exactly what the difference between the sets is? Commented Jan 15, 2015 at 2:34
  • Perhaps something like this? ^edo-apple-iphone-5s-i-gold-16-(edo-(staff|team)-connect|map-(130|95)-handset)-24$? Commented Jan 15, 2015 at 3:09
  • @DavidFaber: Can you modify the script i have to exclude 24 Commented Jan 15, 2015 at 4:27

2 Answers 2

1

The regex that matches the requirements: Not accept if connect-24 OR handset-24 is in the string

^(?:(?!connect-24|handset-24).)*$

DEMO

Sign up to request clarification or add additional context in comments.

2 Comments

Is this based on the length of the string?
@DeepaAranha The old regex partly dependend on the length of the string - the new one doesn't
0

Here is a regular expression that would satisfy the requirement as stated:

.{32,}

Clearly, the strings you want to match are all longer than the ones you don't want to match. This regex matches only those strings that are 32 characters or longer, while edo-apple-iphone-5c-i-yellow-32, the longest non-matching string, has only 31 characters.

2 Comments

Thank you for that. However this will not help. I need to have a regex string that will only accept a string that does not have 24 in it
That's helpful information, but also contradicts what you wrote above. The four strings you want to match above all have 24 in them.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.