+ Reply to Thread
Results 1 to 10 of 10

Thread: Trying to find the first space " " character...

  1. #1
    Barn Regular bryceowen is on a distinguished road bryceowen's Avatar
    Join Date
    Sep 2008
    Location
    Jacksonville, FL
    Posts
    93
    Rep Power
    4

    Trying to find the first space " " character...

    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.
    

  2. #2
    Wolfmaster Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy's Avatar
    Join Date
    Mar 2008
    Location
    Peoria, IL
    Posts
    2,386
    Blog Entries
    5
    Real Name
    Wolff
    Rep Power
    15

    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.

  3. #3
    Barn Regular bryceowen is on a distinguished road bryceowen's Avatar
    Join Date
    Sep 2008
    Location
    Jacksonville, FL
    Posts
    93
    Rep Power
    4

    Thanks for the reply, Wolffy, but that string replaces the entire line in PHP and doesn't work at all in Programmer's Notepad2.

  4. #4
    Barn Regular bryceowen is on a distinguished road bryceowen's Avatar
    Join Date
    Sep 2008
    Location
    Jacksonville, FL
    Posts
    93
    Rep Power
    4

    So far I've got:
    Code:
    (^[\w]+)[ ](?=.)
    
    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 +.

  5. #5
    Wolfmaster Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy's Avatar
    Join Date
    Mar 2008
    Location
    Peoria, IL
    Posts
    2,386
    Blog Entries
    5
    Real Name
    Wolff
    Rep Power
    15

    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.

  6. #6
    Barn Regular bryceowen is on a distinguished road bryceowen's Avatar
    Join Date
    Sep 2008
    Location
    Jacksonville, FL
    Posts
    93
    Rep Power
    4

    What I have is a huge list of names that looks similar to this:
    Code:
    Clinton Bill
    Carter Jimmy
    Bush G H W
    Bush George W
    
    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\tBill
    Carter\tJimmy
    Bush\tG H W
    Bush\tGeorge W
    

  7. #7
    Wolfmaster Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy's Avatar
    Join Date
    Mar 2008
    Location
    Peoria, IL
    Posts
    2,386
    Blog Entries
    5
    Real Name
    Wolff
    Rep Power
    15

    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.

  8. #8
    Barn Regular bryceowen is on a distinguished road bryceowen's Avatar
    Join Date
    Sep 2008
    Location
    Jacksonville, FL
    Posts
    93
    Rep Power
    4

    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...

  9. #9
    Wolfmaster Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy's Avatar
    Join Date
    Mar 2008
    Location
    Peoria, IL
    Posts
    2,386
    Blog Entries
    5
    Real Name
    Wolff
    Rep Power
    15

    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.

  10. #10
    Barn Regular bryceowen is on a distinguished road bryceowen's Avatar
    Join Date
    Sep 2008
    Location
    Jacksonville, FL
    Posts
    93
    Rep Power
    4

    Not exactly the solution I was hoping for, but whatever works, right?

    Thanks for the assist.

+ Reply to Thread

Similar Threads

  1. "UNDEFINED" form value
    By PhloooooIsFlo in forum JavaScript Programming
    Replies: 10
    Last Post: January 8th, 2009, 06:14 AM
  2. Add Eval("") value to OnClientClick Func
    By Shem in forum .NET Development
    Replies: 4
    Last Post: October 13th, 2008, 11:30 AM
  3. excel to access need macro to find space
    By peebman2000 in forum Microsoft Access
    Replies: 6
    Last Post: August 28th, 2008, 12:29 PM
  4. AJAX "post" not "get"
    By dr_rock in forum JavaScript Programming
    Replies: 1
    Last Post: August 7th, 2008, 08:48 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

SEO by vBSEO