“Match anything” is one of the patterns that you can select on the Match panel. This pattern allows a field to match any text, except perhaps for certain characters that may occur in the next field. The repetition settings for the field determine how many characters the field can or must match.
This pattern is actually the first pattern in the list of patterns in RegexMagic because it is the most generic pattern. But it’s the last example in this help file because in most cases you get a more accurate and better performing regular expression by using a more specific pattern. It is very rare that you want to allow part of your regex to match truly any text. Usually there are exceptions. If you do want to use the “match anything pattern”, pay attention to the “match anything except” choice. This example illustrates two of those choices.
For this example, we’ll try to match a pair of HTML bold tags, with any text between them, but no other HTML tags between them.
This is some <b>bold</b> text. This one <b>also</b>. <b>Whatever</b>. Mixing <b>bold and <i>italic</i></b> together.
.
.
. The first sample has been marked now: This is some <b>bold</b> text. This one <b>also</b>. <b>Whatever</b>. Mixing <b>bold and <i>italic</i></b> together.
. Since we only marked one piece of text for this field that doesn’t fit any particular pattern, RegexMagic selected the “literal text” pattern for this field, making it match the word “bold” that we marked.
, which matches the literal text </b>. Thus, excluding the first character of the next field makes field
match any character except an opening angle bracket. This meets our requirement of excluding nested HTML tags.
, enter 1 under “repeat this field” and tick the “unlimited” checkbox. Since we only marked one sample that is 4 characters long, RegexMagic set this field to allow exactly 4 characters. Now we’ve set it to allow any number of characters.
.
.<b>[^\n\r<]+</b>
Required options: Case insensitive.
Unused options: Exact spacing; Dot doesn’t match line breaks; ^$ don’t match at line breaks; Numbered capture.
This is some <b>bold</b> text. This one <b>also</b>. <b>Whatever</b>. Mixing <b>bold and <i>italic</i></b> together.
With a few simple changes, we can generate another regex that matches a pair of HTML bold tags that allows any text in between, including any HTML tags except the closing bold tag.
. This is necessary to ensure that the regex match will end at the first closing tag after the opening tag rather than at the last closing tag in the file.
if not already selected.<b>(?>.+?</b>)
Required options: Case insensitive; Dot doesn’t match line breaks.
Unused options: Exact spacing; ^$ don’t match at line breaks; Numbered capture.
This is some <b>bold</b> text. This one <b>also</b>. <b>Whatever</b>. Mixing <b>bold and <i>italic</i></b> together.