Delete all text before and after a certain string

3

1

I have some URL like the following

http://www.SOMEURL.com/first-category/1343381-example-text-text-text-text-2000-a.html

What I want is to simple delete all of the text before and after the number 1343381 which is an ID.

I read that I could do this using Notepad++ Regular Expressions. Any ideas?

FlKey

Posted 2012-04-18T03:41:54.780

Reputation: 31

Answers

4

If we can assume that SOMEURL and first-category don't contain digits, we can simply search for the first non-empty string of numbers and delete everything else.

Pattern:

Find what:    (.*?)(\d+).*
Replace with: \2

How it works:

  • .* is any arbitrary string of characters

  • ? makes .* lazy, i.e., it matches as few characters as possible

  • \d+ is a non-empty string of digits

  • () groups characters, where \2 refers to the second group

For more information about Regular Expressions, click here.

Example:

http://www.SOMEURL.com/first-category/1343381-example-text-text-text-2000-a.html
http://www.SOMEOTHERURL.com/some-category/1343382-example-more-text-2001-b.html

gets replaced with

1343381
1343382

Dennis

Posted 2012-04-18T03:41:54.780

Reputation: 42 934