x Hint: Register, if you want to hide ads.
x Did you like it? Well, then please consider making a donation :)

Regex Tag - example

Split string to get Date and text

I have to process text file like that: text 01/01/1970 text 02/01/1970 ... etc. I want the output to be the following data: according to the docs, wrapping the string you're splitting on in () (making it a capture group) will result in these captures being included in the array.

Type: split, Date: 8/12/2015 4:38:43 PMAuthor: stackoverflow

How do I replace multiple spaces with a single space?

Replace multiple spaces example

Type: replace, Date: 7/12/2015 4:10:18 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