简体   繁体   中英

using regex to substitute a string expression

I would like to create a pattern using regex. here is an example : dark blue red colored.

basically I wanna use regex to create a pattern that would select the expression whatever the color is. something like dark (word) colored

Can anyone help me please.

The following REGEX allows you to extract the color assuming dark and colored are static.

Matches in this example:

dark red colored - group(3) = red

dark red blue colored - group(6) and group(7) = red blue

^((dark)\s([a-z]*)\s(colored)|(dark)\s([a-z]*)\s([a-z]*)\s(colored))$

正则表达式可视化

Debuggex 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