Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- >>> s = 'Stack Overflow - Ask Questions Here'
- >>> s.split(' - ')
- ['Stack Overflow', 'Ask Questions Here']
- >>> # To get the substring before the match
- >>> s.split(' - ')[0]
- 'Stack Overflow'
- >>> import re
- >>> re.split(' - ', s)[0]
- 'Stack Overflow'
- $sentence = 'Stack Overflow - Ask Questions Here';
- if ($sentence =~ /^(.*?) - /) {
- print "Found match: '$1'n";
- }
- $sentence1 = 'Stack Overflow - Ask Questions Here - And more here';
- $sentence2 = 'Just Stack Overflow';
- $sentence1 =~ /^(.*?)( - |$)/;
- print $1, "n";
- $sentence1 =~ /^(?|(.*) - |(.*)$)/;
- print $1, "n";
- $sentence2 =~ /^(.*?)( - |$)/;
- print $1, "n";
- $sentence2 =~ /^(?|(.*) - |(.*)$)/;
- print $1, "n";
Add Comment
Please, Sign In to add comment