Marek M.
Marek M.

Reputation: 3951

Match all characters except the last if it's a semicolon

I'd like to perform a regexp search operation in python to match everything, but one character (which in this example is at the end):

expression = re.compile(r'http:\/\/.*')

The above regular expression would match whole url: http://stackoverflow.com/questions/ask; and what I want to do is to get a match without the final ; character.

Upvotes: 1

Views: 1734

Answers (1)

Rohit Jain
Rohit Jain

Reputation: 213261

You can use a negated character class instead of dot (.) at the end: -

expression = re.compile(r'http:\/\/[^;]*')

Upvotes: 1

Related Questions