Regular expressions: Difference between revisions
Jump to navigation
Jump to search
(Created page with "<pre>/[A-Z]\.\s[A-Z]/g</pre> Find capital letter, space, capital letter.") |
m (Text replacement - "--" to " — ") |
||
(28 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
<pre>/[A-Z]\. | Find 4-character hex strings: | ||
: ([0-9 A-Z]{4}) | |||
: replace with \1 and font styles styles | |||
Find a space before a digit from 1 to 9: | |||
:<pre>[ ]([1-9])</pre> | |||
: Then put \1 in the replace field to delete the space but keep the digit. | |||
Find everything up to a tab | |||
:<pre>[^\t]+</pre> | |||
Find capital letter, period, space, capital letter, period. | |||
:<pre>([A-Z]\.)[ ]([A-Z]\.)</pre> | |||
Kill the space by using this for the replacement field: | |||
:<pre>$1$2</pre> | |||
Find digit, period, space, digit. | |||
:<pre>([0-9]\.)[ ]([0-9])</pre> | |||
Kill the space by using this for the replacement field: | |||
:<pre>$1$2</pre> | |||
Perl: find uppercase words. | |||
:<pre> \b[[:upper:]]{2,}\b</pre> | |||
find capital letter at the end of a line, insert period before newline | |||
<pre>(\s[[:upper:]])\n | |||
\1\.^p | |||
</pre> | |||
find period, capital letter at the end of a line | |||
:<pre> (\.[[:upper:]])\n </pre> | |||
find lowercase characters one-at-a-time | |||
: <pre>([a-z])</pre> | |||
<pre> | |||
\s\(([0-9]{4}) | |||
\s[[:upper:]]+\r | |||
\L\1\n — lowercases everything | |||
\L2\1\n — inserts 2, space, lowercase of the string | |||
\L$2\1\n — does not insert 2, lowercases string | |||
\U\L\1\n — lowercases everything | |||
</pre> | |||
find ch.vv and change it to ch:vv: | |||
<pre> | |||
^([0-9]+^).^([0-9]+^) = find things like 23.16 | |||
^1:^2 = change the period into a colon 23:16 | |||
</pre> | |||
find M-dash, space, 4-digit number | |||
<pre> | |||
(\ — [ ][0-9]{4}) | |||
<pre> | |||
find footnote marker, period; replace with footnote marker | |||
<pre> | |||
search: (^2). | |||
replace: \1 | |||
</pre> | |||
search for any Unicode character using a DECIMAL number: ^uXXXXXX | |||
== Links == | |||
* [https://www.tutorialspoint.com/perl/perl_regular_expressions.htm Perl Regular Expressions] | |||
* [https://wordmvp.com/FAQs/General/UsingWildcards.htm Using Wildcards in Word] | |||
* [https://regex101.com/ RegEx 101 expression checker] | |||
[[Category:Writing]] |
Latest revision as of 12:18, 10 December 2022
Find 4-character hex strings:
- ([0-9 A-Z]{4})
- replace with \1 and font styles styles
Find a space before a digit from 1 to 9:
[ ]([1-9])
- Then put \1 in the replace field to delete the space but keep the digit.
Find everything up to a tab
[^\t]+
Find capital letter, period, space, capital letter, period.
([A-Z]\.)[ ]([A-Z]\.)
Kill the space by using this for the replacement field:
$1$2
Find digit, period, space, digit.
([0-9]\.)[ ]([0-9])
Kill the space by using this for the replacement field:
$1$2
Perl: find uppercase words.
\b[[:upper:]]{2,}\b
find capital letter at the end of a line, insert period before newline
(\s[[:upper:]])\n \1\.^p
find period, capital letter at the end of a line
(\.[[:upper:]])\n
find lowercase characters one-at-a-time
([a-z])
\s\(([0-9]{4}) \s[[:upper:]]+\r \L\1\n — lowercases everything \L2\1\n — inserts 2, space, lowercase of the string \L$2\1\n — does not insert 2, lowercases string \U\L\1\n — lowercases everything
find ch.vv and change it to ch:vv:
^([0-9]+^).^([0-9]+^) = find things like 23.16 ^1:^2 = change the period into a colon 23:16
find M-dash, space, 4-digit number
(\ — [ ][0-9]{4}) <pre> find footnote marker, period; replace with footnote marker <pre> search: (^2). replace: \1
search for any Unicode character using a DECIMAL number: ^uXXXXXX