Skip to main content
Remove invalid solution + answer clearer + quote important part of the question
Source Link
el-teedee
  • 362
  • 1
  • 4
  • 16

Also I would like to wild card 46, something like ABCCoreUI-*

Workaround: useI think no one answered what you asked "FIX your pattern to match any digit at the end of your string, maybe due to behavior of +* (1 or more) instead ofcharacter at last position, output is concatenating 47+42"

You may wrap the regexp in *'' to prevent (0Shell Globs

Then, to match zero or more) in regexp: digits

sed -r 's/ABCCoreUI-[\d]+[0-9]*/ABCCoreUI-47/' file.json
  • [\d] is to match one digit
  • [\d]+ is to match one to more digits
  • +, unlike *, has no meaning in shell globs, thus you can use it as last caracter in sed regexp

As [Richard][1] said in his comment, the best sould be to prevent [shell globs][2] on the last * by prefixing it with .:

sed -r 's/ABCCoreUI-.*[[:digit:]]*/ABCCoreUI-47/' file.json
  • ABCCoreUI-.* to match "ABCCoreUI-" then 0 or more caracters

And I finally got the regexp toTo match zero or more digits at the end of the regexpzero or more characters

sed -r 's/ABCCoreUI-[[:digit:]]*.*/ABCCoreUI-47/' file.json
  • -r is to enable extended sed regexp
  • [0-9] or [[:digit:]] to match a digit (POSIX) to match a digit
  • [0-9]* or [[:digit:]]* to match zero or more digits
  • .* to match zero or more characters

(still searching a solution to use * if you really need zero or more caracters, as a last caracter of a Note that sed\d regexp) [1]: sed find and replace in file [2]: https://yakking.branchable.com/posts/regexps/is not working.

Workaround: use + (1 or more) instead of * (0 or more) in regexp:

sed 's/ABCCoreUI-[\d]+/ABCCoreUI-47/' file.json
  • [\d] is to match one digit
  • [\d]+ is to match one to more digits
  • +, unlike *, has no meaning in shell globs, thus you can use it as last caracter in sed regexp

As [Richard][1] said in his comment, the best sould be to prevent [shell globs][2] on the last * by prefixing it with .:

sed 's/ABCCoreUI-.*/ABCCoreUI-47/' file.json
  • ABCCoreUI-.* to match "ABCCoreUI-" then 0 or more caracters

And I finally got the regexp to match zero or more digits at the end of the regexp

sed -r 's/ABCCoreUI-[[:digit:]]*/ABCCoreUI-47/' file.json
  • -r to enable extended sed regexp
  • [[:digit:]] to match a digit (POSIX)
  • [[:digit:]]* to match zero or more digits

(still searching a solution to use * if you really need zero or more caracters, as a last caracter of a sed regexp) [1]: sed find and replace in file [2]: https://yakking.branchable.com/posts/regexps/

Also I would like to wild card 46, something like ABCCoreUI-*

I think no one answered what you asked "FIX your pattern to match any digit at the end of your string, maybe due to behavior of * character at last position, output is concatenating 47+42"

You may wrap the regexp in '' to prevent Shell Globs

Then, to match zero or more digits

sed -r 's/ABCCoreUI-[0-9]*/ABCCoreUI-47/' file.json
sed -r 's/ABCCoreUI-[[:digit:]]*/ABCCoreUI-47/' file.json

To match zero or more characters

sed -r 's/ABCCoreUI-.*/ABCCoreUI-47/' file.json
  • -r is to enable extended sed regexp
  • [0-9] or [[:digit:]] (POSIX) to match a digit
  • [0-9]* or [[:digit:]]* to match zero or more digits
  • .* to match zero or more characters

Note that \d is not working.

Add another solution to match zero or more digits
Source Link
el-teedee
  • 362
  • 1
  • 4
  • 16

Workaround: use + (1 or more) instead of * (0 or more) in regexp:

sed 's/ABCCoreUI-[\d]+/ABCCoreUI-47/' file.json
  • [\d] is to match one digit
  • [\d]+ is to match one to more digits
  • +, unlike *, has no meaning in shell globs, thus you can use it as last caracter in sed regexp

As [Richard][1] said in his comment, the best sould be to prevent [shell globs][2] on the last * by prefixing it with .:

sed 's/ABCCoreUI-.*/ABCCoreUI-47/' file.json
  • ABCCoreUI-.* to match "ABCCoreUI-" then 0 or more caracters

And I finally got the regexp to match zero or more digits at the end of the regexp

sed -r 's/ABCCoreUI-[[:digit:]]*/ABCCoreUI-47/' file.json
  • -r to enable extended sed regexp
  • [[:digit:]] to match a digit (POSIX)
  • [[:digit:]]* to match zero or more digits

(still searching a solution to use * if you really need zero or more caracters, as a last caracter of a sed regexp) [1]: sed find and replace in file [2]: https://yakking.branchable.com/posts/regexps/

Workaround: use + (1 or more) instead of * (0 or more) in regexp:

sed 's/ABCCoreUI-[\d]+/ABCCoreUI-47/' file.json
  • [\d] is to match one digit
  • [\d]+ is to match one to more digits
  • +, unlike *, has no meaning in shell globs, thus you can use it as last caracter in sed regexp

As [Richard][1] said in his comment, the best sould be to prevent [shell globs][2] on the last * by prefixing it with .:

sed 's/ABCCoreUI-.*/ABCCoreUI-47/' file.json
  • ABCCoreUI-.* to match "ABCCoreUI-" then 0 or more caracters

(still searching a solution to use * if you really need zero or more caracters, as a last caracter of a sed regexp) [1]: sed find and replace in file [2]: https://yakking.branchable.com/posts/regexps/

Workaround: use + (1 or more) instead of * (0 or more) in regexp:

sed 's/ABCCoreUI-[\d]+/ABCCoreUI-47/' file.json
  • [\d] is to match one digit
  • [\d]+ is to match one to more digits
  • +, unlike *, has no meaning in shell globs, thus you can use it as last caracter in sed regexp

As [Richard][1] said in his comment, the best sould be to prevent [shell globs][2] on the last * by prefixing it with .:

sed 's/ABCCoreUI-.*/ABCCoreUI-47/' file.json
  • ABCCoreUI-.* to match "ABCCoreUI-" then 0 or more caracters

And I finally got the regexp to match zero or more digits at the end of the regexp

sed -r 's/ABCCoreUI-[[:digit:]]*/ABCCoreUI-47/' file.json
  • -r to enable extended sed regexp
  • [[:digit:]] to match a digit (POSIX)
  • [[:digit:]]* to match zero or more digits

(still searching a solution to use * if you really need zero or more caracters, as a last caracter of a sed regexp) [1]: sed find and replace in file [2]: https://yakking.branchable.com/posts/regexps/

add explanation
Source Link
el-teedee
  • 362
  • 1
  • 4
  • 16

Workaround: use + (1 or more) instead of * (0 or more) in regexp:

sed 's/ABCCoreUI-[\d]+/ABCCoreUI-47/' file.json
  • [\d] is to match one digit
  • [\d]+ is to match one to more digits
  • +, unlike *, has no meaning in shell globs, thus you can use it as last caracter in sed regexp

But asAs [Richard][1] said in his comment, the best sould be to prevent [shell globs][2] on the last * by prefixing it with .:

sed 's/\(ABCCoreUI-4.*/ABCCoreUI-47/' file.json
  • ABCCoreUI-.* to match "ABCCoreUI-" then 0 or more caracters

(still searching a solution to use * if you really need zero or more caracters, as a last caracter of a sed regexp) [1]: sed find and replace in file [2]: https://yakking.branchable.com/posts/regexps/

Workaround: use + (1 or more) instead of * (0 or more) in regexp:

sed 's/ABCCoreUI-[\d]+/ABCCoreUI-47/' file.json

But as [Richard][1] said in his comment, the best sould be to prevent [shell globs][2] on the last * by prefixing it with .:

sed 's/\(ABCCoreUI-4.*/ABCCoreUI-47/' file.json

(still searching a solution to use * if you really need zero or more caracters, as a last caracter of a sed regexp) [1]: sed find and replace in file [2]: https://yakking.branchable.com/posts/regexps/

Workaround: use + (1 or more) instead of * (0 or more) in regexp:

sed 's/ABCCoreUI-[\d]+/ABCCoreUI-47/' file.json
  • [\d] is to match one digit
  • [\d]+ is to match one to more digits
  • +, unlike *, has no meaning in shell globs, thus you can use it as last caracter in sed regexp

As [Richard][1] said in his comment, the best sould be to prevent [shell globs][2] on the last * by prefixing it with .:

sed 's/ABCCoreUI-.*/ABCCoreUI-47/' file.json
  • ABCCoreUI-.* to match "ABCCoreUI-" then 0 or more caracters

(still searching a solution to use * if you really need zero or more caracters, as a last caracter of a sed regexp) [1]: sed find and replace in file [2]: https://yakking.branchable.com/posts/regexps/

Point another (maybe better) solution from richard's comment
Source Link
el-teedee
  • 362
  • 1
  • 4
  • 16
Loading
Source Link
el-teedee
  • 362
  • 1
  • 4
  • 16
Loading