FAQ Database Discussion Community

Regex to create a group from an entire line, or just up to a given token

I'm using a JavaScript Regex Engine. The regex ^(.*?)\s*(?=[*\[]).* will capture a group containing all the characters up to a [ or * character. It works well with these lines, matching the entire line and capturing the first section: This should be captured up to here[ but no further] This...

“Optional” end of line $ literal (non greedy)

I would like to make the "end of line" character ($) "optional" (or non-greedy). Meaning, I want to capture a certain pattern at the end of the line, or none. This is the regex I've built: (.+\s*)\s*(?:(\(\s*[xX\*]\s*\d+\s*\))|$) I would like to capture things like Incompatible device (x10) ; Boot sequence...

Python regex: How to match a string at the end of a line in a file?

I need to match a string at the end of a line of a file. The contents of the file are: network1: type: Internal I have made this regex to get the first line but it does not match anything. Note that my code's requirement is that the string which...