Notepad ++ Regexp help

Source: Internet
Author: User
Tags alphabetic character

 

Author: Georg demboski

Notepad ++ Regexp list

Note: In case you have the Plugins installed, try Control + R or in
The menu plugins textfx quick-find/replace to get a sophisticated
Dialogue including a drop down for regular expressions and multi line
Search/replace.

 

In a regular expression, special characters interpreted are:

. Matches any character
( This marks the start of a region for tagging a match; so what's inside () You can use in "Replace with" using/1,/2 etc.
) This marks the end of a tagged region.
/N Where
N is 1 through 9 refers to the first through ninth tagged region when
Replacing. For example, if the search string was Fred ([1-9]) xxx and
Replace string was Sam/1yyy, when applied to fred2xxx this wowould
Generate sam2yyy.
/< This matches the start of a word using scintilla's definitions of words.
/> This matches the end of a word using scintilla's definition of words.
/X This
Allows you to use a character X that wowould otherwise have a special
Meaning. For example,/[wocould be interpreted as [and not as the start
Of a character set.
[...] This
Indicates a set of characters, for example, [ABC] means any of
Characters A, B or C. You can also use ranges, for example [A-Z]
Any lower case character.
[^...] The complement of the characters in the set. For example, [^ A-Za-Z] means any character t an alphabetic character.
^ This matches the start of a line (unless used inside a set, see above ).
$ This matches the end of a line.
* This matches 0 or more times. For example, Sa * m matches SM, Sam, SAAM, saaam and so on.
+ This matches 1 or more times. For example, Sa + M matches Sam, SAAM, saaam and so on.


Source of this information is the scintilla edit component help, but it was adapted to notepad ++ behaviour.

 

Notepad ++ Regexp examples

Important

  • You have to check the box "Regular Expression" in search
    & Replace Dialog
  • When copying the strings out of here, pay close attention
    Not to have additional spaces in front of them! Then the Regexp will
    Not work!

You use a mediawiki (e.g. Wikipedia,
Wikitravel) and
Want to make all headings one "level higher", so a H2 becomes
A H1 etc.

  1. Search ^ = (=)
    Replace with/1
    Click "replace all" to find all headings2. .. 9 (two equal sign
    Characters are required) which begin at line beginning (^) and
    Replace the two equal sign characters by only the last of the two, so
    Eleminating one and having one remaining.
  2. Search = (=) $
    Replace with/1
    Click "replace all" to find
    All headings2. .. 9 (two equal sign characters are required) which end
    At Line ending ($) and to replace the two equal sign characters
    Only the last of the two, so eleminating one and having one remaining.
  3. == title ==Became=
    title =, You're done

You have a document with a lot of dates, which are in German Date
Format (dd. mm. yy) and you 'd like to transform them to sortable format
(Yy-mm-dd). Don't be afraid by the length of the search term-it's
Long, but consiting of pretty easy and short parts.

  1. Search ([^ 0-9]) ([1, 0123] [0-9])/. ([01] [0-9])/. ([0-9] [0-9]) ([^ 0-9])
    Replace with/1/4-/3-/2/5
    Click "replace all" to fetch


    • The day, whose first number can only be 0, 1, 2 or 3
    • The month, whose first number can only be 0 or 1
    • But only if the aggregator is. And not any
      Charcter (.
      Versus /.)
    • But only if no numbers are sourrounding the date,
      Then it
      Might be an IP address instead of a date

    And to write all of this in the opposite order, should t for
    Surroundings. Pay attention: Whatever search matches will be deleted
    And only replaced by the stuff in the replace field, thus it is
    Mangers to have the surroundings in the replace field as well!

  2. 31.12.97Became97-12-31
    And14.08.05Became05-08-14
    And the IP address14.13.14.14Did not
    Change, you're done

You have printed in Windows a file list usingdir /b/s
>filelist.txtTo the file filelist.txt and want
Make local URLs out of them.

  1. Open filelist.txt with notepad ++
  2. Search //
    Replace/
    Click "replace all" to change windows path separator Char/
    Into URL path separator Char/
  3. Search ^ (. *) $
    Replace with file: // 1
    Click "replace all" to addfile:///In
    Beginning of all lines
  4. Depended on your requirements, preceed to escape some
    Characters like space to % 20 etc.
  5. C:/!/aktuell.csvBecamefile:///C:/!/aktuell.csv,
    You're done

 

Another search replace example

[Data]
EU ax Ala 248 land islands
EU Al ALB 008 Albania, people's Socialist Republic
Af dz dza 012 Algeria, People's Democratic Republic
OC as ASM 016 American Samoa
Eu ad and 020 Andorra, Principality
Af ao ago 024 Angola, Republic
Na ai AIA 660 Anguilla
An AQ ata 010 Antarctica (the territory south of 60 deg S)
Na Ag ATG 028 Antigua and Barbuda
Sa ar Arg 032 Argentina, Argentine Republic
As am arm 051 Armenia
Na aw ABW 533 Aruba
OC au aus 036 Australia, Commonwealth

[Searchpattern]
([A-Z] +) ([A-Z] +) ([A-Z] +) ([0-9] + )(.*)

[Replacepattern]
/1,/2,/3,/4,/5

[Finaldata]
As, AF, AFG, 004, Afghanistan
EU, ax, Ala, 248, land islands
EU, Al, ALB, 008, Albania, people's Socialist Republic
AF, DZ, DZA, 012, Algeria, People's Democratic Republic
OC, As, ASM, 016, American Samoa
EU, AD, And, 020, Andorra, Principality
AF, AO, Ago, 024, Angola, Republic
Na, AI, AIA, 660, Anguilla
An, AQ, ATA, 010, Antarctica (the territory south of 60 deg S)
Na, AG, ATG, 028, Antigua and Barbuda
Sa, AR, ARG, 032, Argentina, Argentine Republic
As, am, arm, 051, Armenia
Na, aw, ABW, 533, Aruba
OC, AU, AUS, 036, Australia, Commonwealth

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.