Welcome to Discuss Everything Forums...

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed.


 

Reply to Thread

Post a reply to the thread: How do I delete everything after a certain characters in Perl?

Your Message

Click here to log in

What is the number after 87?

 
 

You may choose an icon for your message from this list

Additional Options

  • Will turn www.example.com into [URL]http://www.example.com[/URL].

Rate Thread

You may rate this thread from 1-star (Terrible) to 5-stars (Excellent) if you wish to do so.

Topic Review (Newest First)

  • 02-26-2013, 02:00 AM
    Jacob

    How do I delete everything after a certain characters in Perl?

    I need to delete everything that comes after certain characters, with exception to the new line, in my code.

    In other words, if my special character was '{' and my code read

    Eating Food {feat. john kong} (Remix)

    After deletion, it would now read

    Eating Food

    Now here comes the tough part. I need to do this with multiple characters, being:
    ( / \ [ ^ - ~ _ " * '

    So if I had multiple lines of code:

    Eating Food *feat. john kong* (Remix)
    Eating Food (feat. john kong) (Remix)
    Eating Food ~feat. john kong~ (Remix)
    Eating Food _feat. john kong_ (Remix)
    Eating Food 'feat. john kong' (Remix)
    Eating Food "feat. john kong" (Remix)
    etc..

    After deletion would print out the same thing as the first deletion.

    I tried
    $line =~ s/[(/\[^-~_"*'].*$//;
    but I keep getting an invalid [] range error

    Is it possible to do this in one line of code?

Posting Permissions

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