I need to grab the first occurrence of this pattern [some-file-name ci] OR [some-file-name-ci.yml ci]
So far I'm able to create this pattern
CONFIG_FILE_PATTERN = /\[(\w*[ _-]ci|\w*[ _-]*\.yml ci|.\w*[ _-]*\.yml ci|.\w*[-_]\w*[ _-]*\.yml ci|\w*[-_]\w*[ _-]*\.yml ci|\w*[-_]\w*[ _-]*\w ci|.\w*[-_]\w*[ _-]*\w ci)\]/i.freeze
This works fine for all cases except when there are multiple hyphens (-) in the file name.
Examples:
[hello-ci.yml ci] # works fine for this
[hello.yml ci] # works fine for this
[hello ci] # works fine for this
[hello-world-ci.yml ci] # does not work for this as the file name now have multiple hyphens
Any help will be appreciated.
/\[([^\]\[]*ci)\]/i. See a Rubular demo. Or,/\[([^\]\[]*[ _-]ci)]/iif there must be space,_or-beforeci