Regex for remove everything after “_” in all anchor Tag [closed]












-2















I want any regex to remove everything after underscore in all anchor Tag e.g



input: <a href="/category_592">Text</a>



Output <a href="/category">Text</a>










share|improve this question













closed as too broad by Wiktor Stribiżew, blhsing, Alejandro, Rob, Toto Nov 21 '18 at 18:02


Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.



















  • This problem is not a good fit for regex. Have you considered parsing the text as HTML instead and then altering the value of all a tags' href attribute?

    – Daniel Farrell
    Nov 21 '18 at 17:02
















-2















I want any regex to remove everything after underscore in all anchor Tag e.g



input: <a href="/category_592">Text</a>



Output <a href="/category">Text</a>










share|improve this question













closed as too broad by Wiktor Stribiżew, blhsing, Alejandro, Rob, Toto Nov 21 '18 at 18:02


Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.



















  • This problem is not a good fit for regex. Have you considered parsing the text as HTML instead and then altering the value of all a tags' href attribute?

    – Daniel Farrell
    Nov 21 '18 at 17:02














-2












-2








-2








I want any regex to remove everything after underscore in all anchor Tag e.g



input: <a href="/category_592">Text</a>



Output <a href="/category">Text</a>










share|improve this question














I want any regex to remove everything after underscore in all anchor Tag e.g



input: <a href="/category_592">Text</a>



Output <a href="/category">Text</a>







regex string notepad++






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 21 '18 at 16:59









engg.Furqanengg.Furqan

61




61




closed as too broad by Wiktor Stribiżew, blhsing, Alejandro, Rob, Toto Nov 21 '18 at 18:02


Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.









closed as too broad by Wiktor Stribiżew, blhsing, Alejandro, Rob, Toto Nov 21 '18 at 18:02


Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.















  • This problem is not a good fit for regex. Have you considered parsing the text as HTML instead and then altering the value of all a tags' href attribute?

    – Daniel Farrell
    Nov 21 '18 at 17:02



















  • This problem is not a good fit for regex. Have you considered parsing the text as HTML instead and then altering the value of all a tags' href attribute?

    – Daniel Farrell
    Nov 21 '18 at 17:02

















This problem is not a good fit for regex. Have you considered parsing the text as HTML instead and then altering the value of all a tags' href attribute?

– Daniel Farrell
Nov 21 '18 at 17:02





This problem is not a good fit for regex. Have you considered parsing the text as HTML instead and then altering the value of all a tags' href attribute?

– Daniel Farrell
Nov 21 '18 at 17:02












1 Answer
1






active

oldest

votes


















0














Although you should avoid parsing HTML with regex, but since this is a case of anchor tag which won't be nested, hence you can do a quick work using regex. Use this regex to match the data in group1 and group2,



(<as+[^>]*?href=["'][^']*?)_.*?(["'])


and replace it with 12 (or $1$2 as per the language)



Check the demo



You haven't mentioned how should the data be replaced in case there are multiple underscores in the href attribute, so for now I have done it in a way where it replaces everything from first occurrence of underscore but you can easily do it for last occurrence of underscore by making the regex as greedy.






share|improve this answer


























  • Thank you very much @pushpesh but this regex work but only first anchor tag, not every one.

    – engg.Furqan
    Nov 21 '18 at 17:41













  • @engg.Furqan: Updated the regex and now it will match with any number of tags. Let me know if you further have any queries.

    – Pushpesh Kumar Rajwanshi
    Nov 21 '18 at 18:17






  • 1





    Really thanks @pushpesh now solved.

    – engg.Furqan
    Nov 21 '18 at 18:34











  • Happy to help Furqan :)

    – Pushpesh Kumar Rajwanshi
    Nov 21 '18 at 18:38











  • Appreciated <3 @pushpesh now I am trying to make regex change uppercase to lowercase in anchor tag like input <a href="/CategoRy_592">Text</a> Output <a href="/category_592">Text</a> I am trying find <a(w*)</a> replase to l$1 can you help me to rectify this. Thanks in advanse

    – engg.Furqan
    Nov 21 '18 at 18:49


















1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Although you should avoid parsing HTML with regex, but since this is a case of anchor tag which won't be nested, hence you can do a quick work using regex. Use this regex to match the data in group1 and group2,



(<as+[^>]*?href=["'][^']*?)_.*?(["'])


and replace it with 12 (or $1$2 as per the language)



Check the demo



You haven't mentioned how should the data be replaced in case there are multiple underscores in the href attribute, so for now I have done it in a way where it replaces everything from first occurrence of underscore but you can easily do it for last occurrence of underscore by making the regex as greedy.






share|improve this answer


























  • Thank you very much @pushpesh but this regex work but only first anchor tag, not every one.

    – engg.Furqan
    Nov 21 '18 at 17:41













  • @engg.Furqan: Updated the regex and now it will match with any number of tags. Let me know if you further have any queries.

    – Pushpesh Kumar Rajwanshi
    Nov 21 '18 at 18:17






  • 1





    Really thanks @pushpesh now solved.

    – engg.Furqan
    Nov 21 '18 at 18:34











  • Happy to help Furqan :)

    – Pushpesh Kumar Rajwanshi
    Nov 21 '18 at 18:38











  • Appreciated <3 @pushpesh now I am trying to make regex change uppercase to lowercase in anchor tag like input <a href="/CategoRy_592">Text</a> Output <a href="/category_592">Text</a> I am trying find <a(w*)</a> replase to l$1 can you help me to rectify this. Thanks in advanse

    – engg.Furqan
    Nov 21 '18 at 18:49
















0














Although you should avoid parsing HTML with regex, but since this is a case of anchor tag which won't be nested, hence you can do a quick work using regex. Use this regex to match the data in group1 and group2,



(<as+[^>]*?href=["'][^']*?)_.*?(["'])


and replace it with 12 (or $1$2 as per the language)



Check the demo



You haven't mentioned how should the data be replaced in case there are multiple underscores in the href attribute, so for now I have done it in a way where it replaces everything from first occurrence of underscore but you can easily do it for last occurrence of underscore by making the regex as greedy.






share|improve this answer


























  • Thank you very much @pushpesh but this regex work but only first anchor tag, not every one.

    – engg.Furqan
    Nov 21 '18 at 17:41













  • @engg.Furqan: Updated the regex and now it will match with any number of tags. Let me know if you further have any queries.

    – Pushpesh Kumar Rajwanshi
    Nov 21 '18 at 18:17






  • 1





    Really thanks @pushpesh now solved.

    – engg.Furqan
    Nov 21 '18 at 18:34











  • Happy to help Furqan :)

    – Pushpesh Kumar Rajwanshi
    Nov 21 '18 at 18:38











  • Appreciated <3 @pushpesh now I am trying to make regex change uppercase to lowercase in anchor tag like input <a href="/CategoRy_592">Text</a> Output <a href="/category_592">Text</a> I am trying find <a(w*)</a> replase to l$1 can you help me to rectify this. Thanks in advanse

    – engg.Furqan
    Nov 21 '18 at 18:49














0












0








0







Although you should avoid parsing HTML with regex, but since this is a case of anchor tag which won't be nested, hence you can do a quick work using regex. Use this regex to match the data in group1 and group2,



(<as+[^>]*?href=["'][^']*?)_.*?(["'])


and replace it with 12 (or $1$2 as per the language)



Check the demo



You haven't mentioned how should the data be replaced in case there are multiple underscores in the href attribute, so for now I have done it in a way where it replaces everything from first occurrence of underscore but you can easily do it for last occurrence of underscore by making the regex as greedy.






share|improve this answer















Although you should avoid parsing HTML with regex, but since this is a case of anchor tag which won't be nested, hence you can do a quick work using regex. Use this regex to match the data in group1 and group2,



(<as+[^>]*?href=["'][^']*?)_.*?(["'])


and replace it with 12 (or $1$2 as per the language)



Check the demo



You haven't mentioned how should the data be replaced in case there are multiple underscores in the href attribute, so for now I have done it in a way where it replaces everything from first occurrence of underscore but you can easily do it for last occurrence of underscore by making the regex as greedy.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 21 '18 at 18:16

























answered Nov 21 '18 at 17:15









Pushpesh Kumar RajwanshiPushpesh Kumar Rajwanshi

10.9k21230




10.9k21230













  • Thank you very much @pushpesh but this regex work but only first anchor tag, not every one.

    – engg.Furqan
    Nov 21 '18 at 17:41













  • @engg.Furqan: Updated the regex and now it will match with any number of tags. Let me know if you further have any queries.

    – Pushpesh Kumar Rajwanshi
    Nov 21 '18 at 18:17






  • 1





    Really thanks @pushpesh now solved.

    – engg.Furqan
    Nov 21 '18 at 18:34











  • Happy to help Furqan :)

    – Pushpesh Kumar Rajwanshi
    Nov 21 '18 at 18:38











  • Appreciated <3 @pushpesh now I am trying to make regex change uppercase to lowercase in anchor tag like input <a href="/CategoRy_592">Text</a> Output <a href="/category_592">Text</a> I am trying find <a(w*)</a> replase to l$1 can you help me to rectify this. Thanks in advanse

    – engg.Furqan
    Nov 21 '18 at 18:49



















  • Thank you very much @pushpesh but this regex work but only first anchor tag, not every one.

    – engg.Furqan
    Nov 21 '18 at 17:41













  • @engg.Furqan: Updated the regex and now it will match with any number of tags. Let me know if you further have any queries.

    – Pushpesh Kumar Rajwanshi
    Nov 21 '18 at 18:17






  • 1





    Really thanks @pushpesh now solved.

    – engg.Furqan
    Nov 21 '18 at 18:34











  • Happy to help Furqan :)

    – Pushpesh Kumar Rajwanshi
    Nov 21 '18 at 18:38











  • Appreciated <3 @pushpesh now I am trying to make regex change uppercase to lowercase in anchor tag like input <a href="/CategoRy_592">Text</a> Output <a href="/category_592">Text</a> I am trying find <a(w*)</a> replase to l$1 can you help me to rectify this. Thanks in advanse

    – engg.Furqan
    Nov 21 '18 at 18:49

















Thank you very much @pushpesh but this regex work but only first anchor tag, not every one.

– engg.Furqan
Nov 21 '18 at 17:41







Thank you very much @pushpesh but this regex work but only first anchor tag, not every one.

– engg.Furqan
Nov 21 '18 at 17:41















@engg.Furqan: Updated the regex and now it will match with any number of tags. Let me know if you further have any queries.

– Pushpesh Kumar Rajwanshi
Nov 21 '18 at 18:17





@engg.Furqan: Updated the regex and now it will match with any number of tags. Let me know if you further have any queries.

– Pushpesh Kumar Rajwanshi
Nov 21 '18 at 18:17




1




1





Really thanks @pushpesh now solved.

– engg.Furqan
Nov 21 '18 at 18:34





Really thanks @pushpesh now solved.

– engg.Furqan
Nov 21 '18 at 18:34













Happy to help Furqan :)

– Pushpesh Kumar Rajwanshi
Nov 21 '18 at 18:38





Happy to help Furqan :)

– Pushpesh Kumar Rajwanshi
Nov 21 '18 at 18:38













Appreciated <3 @pushpesh now I am trying to make regex change uppercase to lowercase in anchor tag like input <a href="/CategoRy_592">Text</a> Output <a href="/category_592">Text</a> I am trying find <a(w*)</a> replase to l$1 can you help me to rectify this. Thanks in advanse

– engg.Furqan
Nov 21 '18 at 18:49





Appreciated <3 @pushpesh now I am trying to make regex change uppercase to lowercase in anchor tag like input <a href="/CategoRy_592">Text</a> Output <a href="/category_592">Text</a> I am trying find <a(w*)</a> replase to l$1 can you help me to rectify this. Thanks in advanse

– engg.Furqan
Nov 21 '18 at 18:49





Popular posts from this blog

Guess what letter conforming each word

Port of Spain

Run scheduled task as local user group (not BUILTIN)