Could someone give me a hand building a regex to find only the first space (" ") character of a line?
For example:
Code:The quick brown fox jumped over the lazy dogs. ^ Find only this space.
Could someone give me a hand building a regex to find only the first space (" ") character of a line?
For example:
Code:The quick brown fox jumped over the lazy dogs. ^ Find only this space.
Try:
Code:^\w+(\s).*$
Wolffy
.-- ----- ..-. ..-. -.--
Opinions expressed are my own and do not necessity reflect those of any sane person. Any code provided is intended to be an example and is provided AS IS. Void where prohibited by law. Not valid in California. Your mileage may vary.
Thanks for the reply, Wolffy, but that string replaces the entire line in PHP and doesn't work at all in Programmer's Notepad2.
So far I've got:
which matches everything up to and including the first space. I tried setting a lookbehind argument like:Code:(^[\w]+)[ ](?=.)
but the regex engine doesn't like lookbehind without a fixed length. This includes {n,m} arguments in lieu of the +.Code:(?<=(^[\w]+))[ ](?=.)
I guess I'm confused as to what you are trying to do. Are you trying to break you input string into separate words, or just break it after the first work, or something else?
Wolffy
.-- ----- ..-. ..-. -.--
Opinions expressed are my own and do not necessity reflect those of any sane person. Any code provided is intended to be an example and is provided AS IS. Void where prohibited by law. Not valid in California. Your mileage may vary.
What I have is a huge list of names that looks similar to this:
As you can see, it's last name, first name/inital and sometimes middle initial, all separated by a space. What I need to do is find only the first space character and replace it with a tab so I can import this list into a database. The end result would be:Code:Clinton Bill Carter Jimmy Bush G H W Bush George W
Code:Clinton\tBill Carter\tJimmy Bush\tG H W Bush\tGeorge W
Hmm...following worked for me, using my editor on your sample data:
Code:^(\w+)(\s)(.*)$ Replacement string: $1\t$3
Wolffy
.-- ----- ..-. ..-. -.--
Opinions expressed are my own and do not necessity reflect those of any sane person. Any code provided is intended to be an example and is provided AS IS. Void where prohibited by law. Not valid in California. Your mileage may vary.
What editor are you using? Using your code in PHP replaces the whole line and Programmer's Notepad doesn't like () in its regex find/replace...
I've been using PSPad for a couple of years. You can down load it for free at
PSPad - free unicode developer editor, handles near any syntax like HTML, PHP, XHTML, JavaScript, ASP, Perl, C and many other languages with HEX editor, multilanguage interface
Note sure why Notepad wouldnt' like () in the regex -- it very valid (and common) syntax. If this is a one time one thing -- I'd probably go that way.
Wolffy
.-- ----- ..-. ..-. -.--
Opinions expressed are my own and do not necessity reflect those of any sane person. Any code provided is intended to be an example and is provided AS IS. Void where prohibited by law. Not valid in California. Your mileage may vary.
Not exactly the solution I was hoping for, but whatever works, right?
Thanks for the assist.
Bookmarks