1

Since i'm not so good at regex how can i match some conditions in a string, StaticString_1number:1number:more than 1number.

Example:

string_3:0:12344555 - Match 
string_s:0:12344555 - No match 
string_3:s:12344555 - No match 
string_3:0:123s4555 - No match

Thanks.

3
  • 4
    What are you trying to match exactly? Commented May 21, 2013 at 9:30
  • 1
    Please provide some sample input and the desired output. Commented May 21, 2013 at 9:31
  • Input - string_3:0:12344555 - it's ok regex matched Input - string_s:0:12344555 - not ok Input - string_3:s:12344555 - not ok Input - string_3:0:123s4555 - not ok Commented May 21, 2013 at 9:35

5 Answers 5

2

This Regex would solve your problem:

^[a-zA-Z]+_[\d]{1}:[\d]{1}:[\d]+$

You can check this link for verification: http://regexr.com?34uj5

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

Comments

1

If I understand your pattern StaticString_1number:1number:more than 1number correctly your regex to match against such strings could look like the following:

'^[a-zA-Z]+_[0-9]:[0-9]:[0-9]+$'

or if your environment support character classes:

'^\w+_\d:\d:\d+$'

Comments

1

This should suit your needs:

^[^_]+_\d:\d:\d+$

Demo

Comments

0

If the initial String can only have characters a-z then the following should work :

[a-z A-Z]+_\d:\d:\d+

this will match any number of letters up to an underscore then look for single digit before and after colon and multiple digits after second colon.

but you should really have an attempt your self. if in python you could try re-try or in javascript regexpal and try out your regex patterns there first.

Comments

0

This may help : ^[a-zA-Z]*_[0-9]:[0-9]:[0-9]*$

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.