I am trying to write a regex that selects everything between two characters.
For example, when the regex encounters a '§'
I want it to select everything after the '§'
sign, up until the point that the regex encounters a ';'
. I tried with a lookbehind and lookahead, but they don't really do the trick.
So for example " § 1-2 bla; "
should return " 1-2 bla"
.
Any help would be greatly appreciated!
In regular expressions, the period ( . , also called "dot") is the wildcard pattern which matches any single character. Combined with the asterisk operator . * it will match any number of any characters.
\\. matches the literal character . . the first backslash is interpreted as an escape character by the Emacs string reader, which combined with the second backslash, inserts a literal backslash character into the string being read. the regular expression engine receives the string \.
Capturing groups are a way to treat multiple characters as a single unit. They are created by placing the characters to be grouped inside a set of parentheses. For example, the regular expression (dog) creates a single group containing the letters "d" "o" and "g" .
\n. Matches a newline character. \r. Matches a carriage return character.
How about
"§([^;]*);"
The selected characters between the §
and ;
are available as match group 1.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With