Grab characters up to a certain character

Discussion in 'Perl Misc' started by imphasing, Apr 21, 2005.

  1. imphasing

    imphasing Guest

    I'm writing a script, that parses a chat log into an html file, and
    I've done a fairly good job so far, it works quite well. But I want to
    make the nickname of a person bold. I have a string like so:

    imphasing: Hi people.

    and I want to replace all the characters up to the ": " with
    "<b>imphasing: </b>"
    I tried an index, but it didn't seem to return the character position
    of ": "...I can't search and replace "imphasing: ", because other
    people are going to be talking too.

    Any ideas? if I could just get the "imphasing: " into a string, it
    would be nice and easy...

    Thanks,
    Alex
     
    imphasing, Apr 21, 2005
    #1
    1. Advertising

  2. At 2005-04-21 12:10PM, imphasing <> wrote:
    > I have a string like so:
    >
    > imphasing: Hi people.
    >
    > and I want to replace all the characters up to the ": " with
    > "<b>imphasing: </b>"


    Try:
    $string =~ s|^(.*?:)|<b>$1</b>|;


    --
    Glenn Jackman
    NCF Sysadmin
     
    Glenn Jackman, Apr 21, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Wendy S
    Replies:
    6
    Views:
    7,536
    Neil Campbell
    Jan 10, 2004
  2. Replies:
    0
    Views:
    664
  3. Michael Onfrek
    Replies:
    7
    Views:
    437
    Michael Onfrek
    Jun 2, 2005
  4. Replies:
    2
    Views:
    535
    bruce barker
    Mar 25, 2008
  5. SAN CAZIANO
    Replies:
    8
    Views:
    184
    Dr John Stockton
    Oct 15, 2004
Loading...

Share This Page