简体   繁体   中英

regular expression to capture the string from the following pattern

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”, ie, : How to write a regular expression to capture Part1. Thanks.

Try this

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

Test Here

(\w+)\s:\s.*

您可以在以下网站上查看正则表达式: https : //regex101.com/

Please try this pattern:

^([^ ]+) : .*$

REGEX DEMO.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM