Regex. Greedy and lazy quantifiers [duplicate]



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








-1
















This question already has an answer here:



  • Non-greedy match is still too greedy

    2 answers



I have this string:



a = 'one\two\three.txt';


I want to get "three.txt". And this:



a.match(/\(.+?)$/)


Doesn't work. Why? How can I get "three.txt"?










share|improve this question













marked as duplicate by Wiktor Stribiżew javascript
Users with the  javascript badge can single-handedly close javascript 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 14 '18 at 8:42


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.













  • 1





    Doesn't work. Why? Because it doesn't match.

    – Foo
    Nov 14 '18 at 5:01











  • So, why don't you use split? 'one\two\three.txt'.split('\')

    – Foo
    Nov 14 '18 at 5:04

















-1
















This question already has an answer here:



  • Non-greedy match is still too greedy

    2 answers



I have this string:



a = 'one\two\three.txt';


I want to get "three.txt". And this:



a.match(/\(.+?)$/)


Doesn't work. Why? How can I get "three.txt"?










share|improve this question













marked as duplicate by Wiktor Stribiżew javascript
Users with the  javascript badge can single-handedly close javascript 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 14 '18 at 8:42


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.













  • 1





    Doesn't work. Why? Because it doesn't match.

    – Foo
    Nov 14 '18 at 5:01











  • So, why don't you use split? 'one\two\three.txt'.split('\')

    – Foo
    Nov 14 '18 at 5:04













-1












-1








-1


1







This question already has an answer here:



  • Non-greedy match is still too greedy

    2 answers



I have this string:



a = 'one\two\three.txt';


I want to get "three.txt". And this:



a.match(/\(.+?)$/)


Doesn't work. Why? How can I get "three.txt"?










share|improve this question















This question already has an answer here:



  • Non-greedy match is still too greedy

    2 answers



I have this string:



a = 'one\two\three.txt';


I want to get "three.txt". And this:



a.match(/\(.+?)$/)


Doesn't work. Why? How can I get "three.txt"?





This question already has an answer here:



  • Non-greedy match is still too greedy

    2 answers







javascript regex






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 14 '18 at 4:59









ДмитрийДмитрий

1113




1113




marked as duplicate by Wiktor Stribiżew javascript
Users with the  javascript badge can single-handedly close javascript 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 14 '18 at 8:42


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 javascript
Users with the  javascript badge can single-handedly close javascript 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 14 '18 at 8:42


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.









  • 1





    Doesn't work. Why? Because it doesn't match.

    – Foo
    Nov 14 '18 at 5:01











  • So, why don't you use split? 'one\two\three.txt'.split('\')

    – Foo
    Nov 14 '18 at 5:04












  • 1





    Doesn't work. Why? Because it doesn't match.

    – Foo
    Nov 14 '18 at 5:01











  • So, why don't you use split? 'one\two\three.txt'.split('\')

    – Foo
    Nov 14 '18 at 5:04







1




1





Doesn't work. Why? Because it doesn't match.

– Foo
Nov 14 '18 at 5:01





Doesn't work. Why? Because it doesn't match.

– Foo
Nov 14 '18 at 5:01













So, why don't you use split? 'one\two\three.txt'.split('\')

– Foo
Nov 14 '18 at 5:04





So, why don't you use split? 'one\two\three.txt'.split('\')

– Foo
Nov 14 '18 at 5:04












1 Answer
1






active

oldest

votes


















0














You can use this regex: [w.]+?$

Details at regex101: https://regex101.com/r/n8HyiL/1

Or remove the ? it's still ok!






share|improve this answer





























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    You can use this regex: [w.]+?$

    Details at regex101: https://regex101.com/r/n8HyiL/1

    Or remove the ? it's still ok!






    share|improve this answer



























      0














      You can use this regex: [w.]+?$

      Details at regex101: https://regex101.com/r/n8HyiL/1

      Or remove the ? it's still ok!






      share|improve this answer

























        0












        0








        0







        You can use this regex: [w.]+?$

        Details at regex101: https://regex101.com/r/n8HyiL/1

        Or remove the ? it's still ok!






        share|improve this answer













        You can use this regex: [w.]+?$

        Details at regex101: https://regex101.com/r/n8HyiL/1

        Or remove the ? it's still ok!







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 14 '18 at 5:06









        protoprotoprotoproto

        1,013710




        1,013710















            Popular posts from this blog

            Malaysia to Papua New Guinea by motorcycle?

            List of Bhojpuri films

            PHP code is not being executed, instead code shows on the page