Regex tricks: Difference between revisions

From The Jolly Contrarian
Jump to navigation Jump to search
No edit summary
 
(14 intermediate revisions by the same user not shown)
Line 1: Line 1:
===Seach destroy===
==Microsoft Word==
/\{\{fullanat2\|isda\|([^]]*)\|2002\|[^]]*\|1992\}\}/ ==> <nowiki>{{isdaanat|$1}}</nowiki>
Find unpunctuated text: ([A-z ]{1,})
Find unpunctuated text with curly brackets: ([A-z \{\}]{1,})
Find punctuated text inside square brackets: \[[a-z,A-Z,0-9 \.\/\,\:]{1,}\]  
===Paragraph wrap===
Find “paragraph 9(i)(a),” and wrap with prov tag:
Find: Paragraph <nowiki>([0-9\(\)][!.,; ]{1,})</nowiki>
Replace: Paragraph <nowiki>{{nycsaprov|\1}}</nowiki>


If your numbering schema has full stops in it try this:
Find: Clause <nowiki>([0-9\(\).][!,; ]{1,})</nowiki>
Replace: Clause <nowiki>{{ietaprov|\1}}</nowiki>
===Indenting wikified autonumbering===
*In a word doc, make all your numbering reveal every level (eg “13(c)(vii)(B)” with the ferocity of a US securities lawyer. you can do this in the “Define Multilevel Lists” dialogue.
*Copy your whole doc into a text-only email. It will faithfully convert all those numbers to text. You will lose the indenting. We will put it back.
*Switch on Use wildcards in the replace dialogue.
Find: ^13([0-9]{1,}\([a-z,A-Z,0-9]{1,}\)\([a-z,A-Z,0-9]{1,}\)\([a-z,A-Z,0-9]{1,}\))
Replace: ^13:::\1
Then
Find: ^13([0-9]{1,}\([a-z,A-Z,0-9]{1,}\)\([a-z,A-Z,0-9]{1,}\))
Replace: ^13::\1
Then
Find: ^13([0-9]{1,}\([a-z,A-Z,0-9]{1,}\))
Replace: ^13:\1
Sorted.
EVEN BETTER THAN THAT:
In the define multilevel dialogue, add the necessary number of indenting colons into the actual word numbering
===Macro Magic===
===Tagging everything coloured blue===
===Tagging everything coloured blue===
#search and destroy
#search and destroy
Line 33: Line 63:


Mwah.
Mwah.
===Indenting wikified autonumbering===
*In a word doc, make all your numbering reveal every level (eg “13(c)(vii)(B)” with the ferocity of a US securities lawyer. you can do this in the “Define Multilevel Lists” dialogue.
*Copy your whole doc into a text-only email. It will faithfully convert all those numbers to text. You will lose the indenting. We will put it back.
*Switch on Use wildcards in the replace dialogue.
:*Find: ^13([0-9]{1,}\([a-z,A-Z,0-9]{1,}\)\([a-z,A-Z,0-9]{1,}\)\([a-z,A-Z,0-9]{1,}\))
:*Replace: ^13:::\1
Then
:*Find: ^13([0-9]{1,}\([a-z,A-Z,0-9]{1,}\)\([a-z,A-Z,0-9]{1,}\))
:*Replace: ^13::\1
Then
:*Find: ^13([0-9]{1,}\([a-z,A-Z,0-9]{1,}\))
:*Replace: ^13:\1


Sorted.
==Mediawiki==
====Detagging====
Make sure to tick regular expression in the search and replace box. Then (this if for an isdaprov; change as necessary)
\{\{isdaprov\|([A-z 1234567890. ’()]{1,})\}\} ===> $1
For an nman template, it should be easier: just do this:
 
\{\{ \{\{\{1\}\}\}\|([A-z 1234567890. ’()]{1,})\}\} ===> $1
 
===Any character and page blanking===
To blank a page, first convert all newlines to <nowiki><br></nowiki>s:
/\n/  ==> <nowiki><br></nowiki>
Then convert all text (which now won’t include newlines):
.{1,} ==> <nowiki>{{jcpull}}</nowiki>
===Newmanualising===
<nowiki>/{{manual\|DEQ\|2002\|([A-z 1234567890. ’()]{1,}).{1,}/</nowiki> ==> <nowiki>{{edqmanual|$1}}</nowiki>
===Search destroy===
Convert a fullanat2 into an ISDA anat:
Find /\{\{fullanat2\|isda\|([^]]*)\|2002\|[^]]*\|1992\}\}/
Replace<nowiki>{{isdaanat|$1}}</nowiki>
Delete a redundant  Equity Derivative Nuts:
Find: /\{\{eqderivanat\|([0-9]*.[0-9]*\([a-z]*\))}}/
/\{\{nuts\|Equity Derivatives\|[0-9]*.[0-9]*\([a-z]*\)\}\}/ 
Replace: <nowiki>{{eqderivanat|$1}}</nowiki>

Latest revision as of 07:57, 25 October 2024

Microsoft Word

Find unpunctuated text: ([A-z ]{1,}) Find unpunctuated text with curly brackets: ([A-z \{\}]{1,}) Find punctuated text inside square brackets: \[[a-z,A-Z,0-9 \.\/\,\:]{1,}\]

Paragraph wrap

Find “paragraph 9(i)(a),” and wrap with prov tag:

Find: Paragraph ([0-9\(\)][!.,; ]{1,})
Replace: Paragraph {{nycsaprov|\1}}

If your numbering schema has full stops in it try this:

Find: Clause ([0-9\(\).][!,; ]{1,})
Replace: Clause {{ietaprov|\1}}

Indenting wikified autonumbering

  • In a word doc, make all your numbering reveal every level (eg “13(c)(vii)(B)” with the ferocity of a US securities lawyer. you can do this in the “Define Multilevel Lists” dialogue.
  • Copy your whole doc into a text-only email. It will faithfully convert all those numbers to text. You will lose the indenting. We will put it back.
  • Switch on Use wildcards in the replace dialogue.
Find: ^13([0-9]{1,}\([a-z,A-Z,0-9]{1,}\)\([a-z,A-Z,0-9]{1,}\)\([a-z,A-Z,0-9]{1,}\))
Replace: ^13:::\1

Then

Find: ^13([0-9]{1,}\([a-z,A-Z,0-9]{1,}\)\([a-z,A-Z,0-9]{1,}\))
Replace: ^13::\1

Then

Find: ^13([0-9]{1,}\([a-z,A-Z,0-9]{1,}\))
Replace: ^13:\1

Sorted.

EVEN BETTER THAN THAT: In the define multilevel dialogue, add the necessary number of indenting colons into the actual word numbering

Macro Magic

Tagging everything coloured blue

  1. search and destroy
  • double spaces
  • Fields (ctrl-shift-F9)
  • bookmarks - there's a cool macro for this:
Sub RemoveAllBookmarks()

    Dim objBookmark As bookmark

    For Each objBookmark In ActiveDocument.Bookmarks

        objBookmark.Delete

    Next

End Sub
  1. . Clear out all blue dashes - replace them with xxx
  2. . Clear out all blue apostrophes - replace them with yyy
  3. . Clear ot all blue spaces - replace them with qqq (this won't do the ones either side of the blue phrase)
  • Find: ([A-Z][a-z]{1,}) ([A-Z][a-z]{1,}) (use wildcards, font colour: blue)
  • Replace: \1qqq/2
  1. . Now your tags are all continuous blue strings. So brace them:
  • Find: <(?{1,})> (use wildcards, font colour: blue)
  • Replace: {{wikitag|\1}} (font colour blue)

Now restore spaces, apostrophes and dashes.

Mwah.

Mediawiki

Detagging

Make sure to tick regular expression in the search and replace box. Then (this if for an isdaprov; change as necessary)

\{\{isdaprov\|([A-z 1234567890. ’()]{1,})\}\} ===> $1

For an nman template, it should be easier: just do this:

\{\{ \{\{\{1\}\}\}\|([A-z 1234567890. ’()]{1,})\}\} ===> $1

Any character and page blanking

To blank a page, first convert all newlines to <br>s:

/\n/  ==> <br>

Then convert all text (which now won’t include newlines):

.{1,} ==> {{jcpull}}

Newmanualising

/{{manual\|DEQ\|2002\|([A-z 1234567890. ’()]{1,}).{1,}/ ==> {{edqmanual|$1}}

Search destroy

Convert a fullanat2 into an ISDA anat:

Find /\{\{fullanat2\|isda\|([^]]*)\|2002\|[^]]*\|1992\}\}/ 
Replace{{isdaanat|$1}}

Delete a redundant Equity Derivative Nuts:

Find: /\{\{eqderivanat\|([0-9]*.[0-9]*\([a-z]*\))}}/ 
/\{\{nuts\|Equity Derivatives\|[0-9]*.[0-9]*\([a-z]*\)\}\}/  
Replace: {{eqderivanat|$1}}