x Did you like it? Well, then please consider making a donation :)

Regex Library

Get IP address - simple non capturing example

?: is used when you want to group an expression, but you do not want to save it as a matched/captured portion of the string. An example would be something to match an IP address: (?:\d{1,3}\.){3}\d{1,3} Note that I don't care about saving the first 3 octets, but the (?:...) grouping allows me to shorten the regex without incurring the overhead of capturing and storing a match.

Type: match, Date: 7/12/2015 3:29:13 PMAuthor: stackoverflow

How to get numbers 1st, 2nd, 3rd, 4th from text

You can use capturing groups to organize and parse an expression. A non-capturing group has the first benefit, but doesn't have the overhead of the second. You can still say a non-capturing group is optional, for example. Say you want to match numeric text, but some numbers could be written as 1st, 2nd, 3rd, 4th... If you want to capture the numeric part, but not the (optional) suffix you can use a non-capturing group. ([0-9]+)(?:st|nd|rd|th)? That will match numbers in the form 1, 2, 3... or in the form 1st, 2nd, 3rd,... but it will only capture the numeric part.

Type: match, Date: 7/12/2015 3:26:19 PMAuthor: stackoverflow

Simple example - non capturing group

If I apply the regex below over it: (http|ftp)://([^/\r\n]+)(/[^\r\n]*)? I would get the following result: Match "http://stackoverflow.com/" Group 1: "http" Group 2: "stackoverflow.com" Group 3: "/" But I don't care about the protocol - I just want the host and path of the URL. So, I change the regex to include the non-capturing group (?:): (?:http|ftp)://([^/\r\n]+)(/[^\r\n]*)? Now, my result looks like this: Match "http://stackoverflow.com/" Group 1: "stackoverflow.com" Group 2: "/"

Type: match, Date: 7/12/2015 3:23:20 PMAuthor: stackoverflow

Regex - \d is less efficient than [0-9] - get ALL Unicode digits

\d checks all Unicode digits, while [0-9] is limited to these 10 characters. For example, Persian digits, ?????????, are an example of Unicode digits which are matched with \d, but not [0-9]. [0-9] isn't equivalent to \d. [0-9] matches only 0123456789 characters, while \d matches [0-9] and other digit characters, for example Eastern Arabic numerals ٠١٢٣٤٥٦٧٨٩

Type: match, Date: 7/12/2015 2:34:00 PMAuthor: stackoverflow

Splitting Link using RegEx

i want to find category from the link. I am breaking the link into array using Regex.

Type: split, Date: 3/31/2015 5:40:43 PMAuthor: admin