Regex for remove everything after “_” in all anchor Tag [closed]
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++
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.
add a comment |
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++
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 alla
tags'href
attribute?
– Daniel Farrell
Nov 21 '18 at 17:02
add a comment |
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++
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++
regex string notepad++
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 alla
tags'href
attribute?
– Daniel Farrell
Nov 21 '18 at 17:02
add a comment |
This problem is not a good fit for regex. Have you considered parsing the text as HTML instead and then altering the value of alla
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
add a comment |
1 Answer
1
active
oldest
votes
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.
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
tol$1
can you help me to rectify this. Thanks in advanse
– engg.Furqan
Nov 21 '18 at 18:49
|
show 5 more comments
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
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.
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
tol$1
can you help me to rectify this. Thanks in advanse
– engg.Furqan
Nov 21 '18 at 18:49
|
show 5 more comments
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.
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
tol$1
can you help me to rectify this. Thanks in advanse
– engg.Furqan
Nov 21 '18 at 18:49
|
show 5 more comments
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.
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.
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
tol$1
can you help me to rectify this. Thanks in advanse
– engg.Furqan
Nov 21 '18 at 18:49
|
show 5 more comments
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
tol$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
|
show 5 more comments
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