简体   繁体   中英

Regex Expression Issue with commit Message

Need this type of Commit Message

TaskId : 123456 - commit message
TaskId: 123456 - commit message
TaskId:123456 - commit message
TaskId:123456- commit message
TaskIds : 123456**,123456** ( This Can be multiple times with space without space ) - commit message
TaskIds : 123456**and 123456** ( This Can be multiple times with space without space ) - commit message
Task id - 1233443:commit message 

I have tried this regex but few things are missing

[Tt][Aa][Ss][Kk][Ss]?\s*(?:[Ii][Dd])?\s*[: \s-]?(\s*(?:,|and)?\s*\d+)?\s*(?:\s*)

Expected output is:

$1 = (TaskId:123456,123456) In the commit message on Bitbucket This should be a Link to my custom task system

For Ex:
**https://abc.xyz.com?taskid=$1**

Removing the comments from the text, then I assume what you want to match is: (and similar variants)

TaskId : 123456 - commit message
TaskId: 123456 - commit message
TaskId:123456 - commit message
TaskId:123456- commit message
TaskIds : 123456, 123456 - commit message
TaskIds : 123456 and 123456 - commit message
Task id - 1233443:commit message 

Instead of [Tt][Aa][Ss][Kk][Ss]? then you could also use the insensitive flag and change that part to tasks?

If you want to limit (\s*(?:,|and)?\s*\d+)* to only accept a single , / and , then you can flip it around, ie match \d+ and then zero-to-many ", number" . In short (?:(\d+)(?:\s*(?:,|and)\s*(\d+))*) .

The final pattern could look something like this:

^task(?:\s*ids?)\s*[:-]\s*(?:(\d+)(?:\s*(?:,|and)\s*(\d+))*)\s*[:-]\s*(.*)$

Demo on Regex101

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