LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-17-2012, 03:49 PM   #1
prayag_pjs
Senior Member
 
Registered: Feb 2008
Location: Pune - India
Distribution: RHEL/Ubuntu/Debian/Fedora/Centos/K3OS
Posts: 1,159
Blog Entries: 4

Rep: Reputation: 149Reputation: 149
Question regular expression for example.*


Hi,

I want a regular expression matching anything after "."

For example i have three :

spam.asdfasdf2234s
spam.898HY^%
spam.%^^HHG^%$FVV

I want a regular expression which matches anything after spam.

I have one, let me know if its correct

Code:
/^spam.*/i
I will be using it for header __ X-Mailer in Spamssasin
 
Old 02-17-2012, 04:00 PM   #2
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,836
Blog Entries: 1

Rep: Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251
Quote:
Originally Posted by prayag_pjs View Post
Hi,

I want a regular expression matching anything after "."

For example i have three :

spam.asdfasdf2234s
spam.898HY^%
spam.%^^HHG^%$FVV

I want a regular expression which matches anything after spam.

I have one, let me know if its correct

Code:
/^spam.*/i
I will be using it for header __ X-Mailer in Spamssasin
I don't know much about spamassassin syntax, but generally in regex this will match any line starting with "spam" (the whole line) not just the bit after the spam.
 
Old 02-17-2012, 04:00 PM   #3
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
that would work, but it's not nearly as good as it can be.

firstly the . there is a special character, meaning "a character", not a literal period. so that will match anything. and the * means match that last thing zero or more times. so "spam" itself would match it, as would "spamx123" neither of which fit your examples. if you do "^spam\..+" that will match strings when there is *one* character or more after a real period mark.
 
Old 02-17-2012, 04:40 PM   #4
uhelp
Member
 
Registered: Nov 2011
Location: Germany, Bavaria, Nueremberg area
Distribution: openSUSE, Debian, LFS
Posts: 205

Rep: Reputation: 43
Code:
/spam\.\(.*\)/

/      begin of regex
spam   matched literally
\.     one dot, as the special meaning of "." is escaped by "\"
\(     starting a backreference; expression within ( ) can 
       later be referenced with \1 for the first pair of ()
       \2 for the second and so on
.*     "." means any character (each and every except 0x00 
       depending on implementaion)
       * means zero or unlimited count of characters. use +* if
       there must be at least one character
\)     end of the first backreference group
/      end of regex
Some regex implementations use \( some just a ( to denote a backreference
have a look in spamassins man page

Last edited by uhelp; 02-17-2012 at 04:42 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
regular expression Ammad Linux - General 5 08-01-2008 07:41 AM
regular expression (.*?) uttam_h Programming 6 05-30-2008 05:45 PM
regular expression [tT]h* sycamorex Programming 3 01-15-2008 04:43 PM
Regular Expression slizadel Programming 4 07-28-2003 05:16 AM
regular expression gumby Programming 3 07-15-2003 12:13 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:02 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration