regex match either in the begining or a word with space before [duplicate]












0















This question already has an answer here:




  • Python regular expression match whole word

    4 answers



  • Regex whitespace word boundary

    2 answers




How should I write a regex that would indicate that important is in the string:



df_loc = pd.DataFrame({'cond':['important', 'blabl unimportant', 'blabl important']})


blabla important blabl and important blabl



so, that something like



blabla unimportant blabl and unimportant blabl



would not match.



For important blabl, it would be something like



df_loc['cond'].str.contains(r'^important')


but I am not catching 'blabl important'










share|improve this question















marked as duplicate by Wiktor Stribiżew python
Users with the  python badge can single-handedly close python questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 12 '18 at 17:25


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.











  • 6




    Read about word boundaries, which are supported by Python. Essentially you want the regex r'bimportantb', so you don't match unimportant or importantly.
    – jdehesa
    Nov 12 '18 at 17:13


















0















This question already has an answer here:




  • Python regular expression match whole word

    4 answers



  • Regex whitespace word boundary

    2 answers




How should I write a regex that would indicate that important is in the string:



df_loc = pd.DataFrame({'cond':['important', 'blabl unimportant', 'blabl important']})


blabla important blabl and important blabl



so, that something like



blabla unimportant blabl and unimportant blabl



would not match.



For important blabl, it would be something like



df_loc['cond'].str.contains(r'^important')


but I am not catching 'blabl important'










share|improve this question















marked as duplicate by Wiktor Stribiżew python
Users with the  python badge can single-handedly close python questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 12 '18 at 17:25


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.











  • 6




    Read about word boundaries, which are supported by Python. Essentially you want the regex r'bimportantb', so you don't match unimportant or importantly.
    – jdehesa
    Nov 12 '18 at 17:13
















0












0








0








This question already has an answer here:




  • Python regular expression match whole word

    4 answers



  • Regex whitespace word boundary

    2 answers




How should I write a regex that would indicate that important is in the string:



df_loc = pd.DataFrame({'cond':['important', 'blabl unimportant', 'blabl important']})


blabla important blabl and important blabl



so, that something like



blabla unimportant blabl and unimportant blabl



would not match.



For important blabl, it would be something like



df_loc['cond'].str.contains(r'^important')


but I am not catching 'blabl important'










share|improve this question
















This question already has an answer here:




  • Python regular expression match whole word

    4 answers



  • Regex whitespace word boundary

    2 answers




How should I write a regex that would indicate that important is in the string:



df_loc = pd.DataFrame({'cond':['important', 'blabl unimportant', 'blabl important']})


blabla important blabl and important blabl



so, that something like



blabla unimportant blabl and unimportant blabl



would not match.



For important blabl, it would be something like



df_loc['cond'].str.contains(r'^important')


but I am not catching 'blabl important'





This question already has an answer here:




  • Python regular expression match whole word

    4 answers



  • Regex whitespace word boundary

    2 answers








python regex






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 12 '18 at 17:11









petezurich

3,50581734




3,50581734










asked Nov 12 '18 at 17:10









Tonja

8321648




8321648




marked as duplicate by Wiktor Stribiżew python
Users with the  python badge can single-handedly close python questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 12 '18 at 17:25


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






marked as duplicate by Wiktor Stribiżew python
Users with the  python badge can single-handedly close python questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 12 '18 at 17:25


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.










  • 6




    Read about word boundaries, which are supported by Python. Essentially you want the regex r'bimportantb', so you don't match unimportant or importantly.
    – jdehesa
    Nov 12 '18 at 17:13
















  • 6




    Read about word boundaries, which are supported by Python. Essentially you want the regex r'bimportantb', so you don't match unimportant or importantly.
    – jdehesa
    Nov 12 '18 at 17:13










6




6




Read about word boundaries, which are supported by Python. Essentially you want the regex r'bimportantb', so you don't match unimportant or importantly.
– jdehesa
Nov 12 '18 at 17:13






Read about word boundaries, which are supported by Python. Essentially you want the regex r'bimportantb', so you don't match unimportant or importantly.
– jdehesa
Nov 12 '18 at 17:13














0






active

oldest

votes

















0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes

Popular posts from this blog

The Sandy Post

Danny Elfman

Pages that link to "Head v. Amoskeag Manufacturing Co."