ArtsAutosBooksBusinessEducationEntertainmentFamilyFashionFoodGamesGenderHealthHolidaysHomeHubPagesPersonal FinancePetsPoliticsReligionSportsTechnologyTravel
  • »
  • Technology»
  • Internet & the Web

Regular Expression with HTML and LaTeX code

Updated on January 18, 2011

When searching and replacing, one has to define the text to be found. This can be the text itself, but often it is necessary to define the strings in a more powerful way to avoid repeating the same operation many times. Regular Express (also 'regex') is powerful but sometimes very tricky, one of the many reasons is the variety of text format, and there seems not best way to define a regular expressions, as long as you get the job done.

Below are some tips joted down when I was dealing with Latex and html code, these might be useful to you.

To remove \section mark and its curly parentheses using regex:


use \ to escape back slash or left {, or right }, ^} means there are no parentheses between two {}.

replace with:


\1 back references to contents inside the ().

To replace something like "I. First year." into \section{I. First year.}


two newline, then begin Roman Number I, or V, or X, then zero or more I-X, then one or more space plus word between two dots.


To replace the left quotation marks:

The left quotation marks is one of famous problem in TeX or Latex, to find a left quote and replace with a `


To find uppercase string

Now I have some text like these:

right and wrong, and which condemns all fear or hope of an unknown and unseen world.

[here three newline character \n\n\n]


One of the most curious and harmless customs of the Chinese is that of

I need to find uppercase string, and add html tag <h2> at the start, and </h2> the end.


to replace with:



    0 of 8192 characters used
    Post Comment

    • smga22 profile image

      smga22 3 years ago from Dhaka, Bangladesh

      Nice Hub. Thanks for sharing this hub.