0

There is a string having the following pattern

Part1 : Part2

Part1 is a string without any “space” inside it, or this string can include anything except “space”. Part2 is another string which can have “space” inside. Between Part1 and Part2, the separator is “space””:””space”, i.e., : How to write a regular expression to capture Part1. Thanks.

Yusuf K.
  • 4,195
  • 1
  • 33
  • 69
user288609
  • 12,465
  • 26
  • 85
  • 127

3 Answers3

0

Try this

(.*?)(?>\s:)

Test Here

Pragnani
  • 20,075
  • 6
  • 49
  • 74
  • I test this regex using abcd\eft : abdeff::, and get abcd\eft : I changed this regex to (.*?) in order to get abcd\eft only, but it did not work? May I know the reason? Thanks. – user288609 Mar 17 '16 at 16:10
  • @user288609 you should get the group.. Can show your code – Pragnani Mar 17 '16 at 18:09
  • What do you mean "you should get the group"? I am a little bit lost. Thanks. – user288609 Mar 17 '16 at 18:47
  • @user288609 Check this http://stackoverflow.com/questions/432493/how-do-you-access-the-matched-groups-in-a-javascript-regular-expression – Pragnani Mar 18 '16 at 08:12
0
(\w+)\s:\s.*

You can check regex at this website : https://regex101.com/

themadmax
  • 2,344
  • 1
  • 31
  • 36
0

Please try this pattern:

^([^ ]+) : .*$

REGEX DEMO.

Quinn
  • 4,394
  • 2
  • 21
  • 19