I have a Debian machine with Kate Version 16.08.3 .
I wish to do a search & replace using regular expressions.
The "Help" menu has led to https://docs.kde.org/stable5/en/kate/katepart/regular-expressions.html
and
https://docs.kde.org/stable5/en/kate/katepart/regex-patterns.html
I have strings of the form "XYZn" where n is one to three digits
representing values of from 1 to 299. I wish to replace all occurrences
with "abc".
The documents give essentially no examples.
Help please.
TIA
Richard Owlett <[email protected]> wrote at 14:40 this Tuesday (GMT):
I have a Debian machine with Kate Version 16.08.3 .
I wish to do a search & replace using regular expressions.
The "Help" menu has led to
https://docs.kde.org/stable5/en/kate/katepart/regular-expressions.html
and
https://docs.kde.org/stable5/en/kate/katepart/regex-patterns.html
I have strings of the form "XYZn" where n is one to three digits
representing values of from 1 to 299. I wish to replace all occurrences
with "abc".
The documents give essentially no examples.
Help please.
TIA
I'd recommend using an online regex generator like
https://regex101.com/.
This regex expression should do what you want:
[[:digit:]]{3}
I have a Debian machine with Kate Version 16.08.3 .
I wish to do a search & replace using regular expressions.
The "Help" menu has led to https://docs.kde.org/stable5/en/kate/katepart/regular-expressions.html
and
https://docs.kde.org/stable5/en/kate/katepart/regex-patterns.html
I have strings of the form "XYZn" where n is one to three digits
representing values of from 1 to 299. I wish to replace all occurrences
with "abc".
The documents give essentially no examples.
Help please.
TIA
Richard Owlett <[email protected]> wrote at 14:40 this Tuesday (GMT):
I have a Debian machine with Kate Version 16.08.3 .
I wish to do a search & replace using regular expressions.
The "Help" menu has led to
https://docs.kde.org/stable5/en/kate/katepart/regular-expressions.html
and
https://docs.kde.org/stable5/en/kate/katepart/regex-patterns.html
I have strings of the form "XYZn" where n is one to three digits
representing values of from 1 to 299. I wish to replace all occurrences
with "abc".
The documents give essentially no examples.
Help please.
TIA
I'd recommend using an online regex generator like
https://regex101.com/.
Unfortunately it seems your browser does not meet the criteria to
properly render and utilize this website. You need a browser with
support for web workers and Web Assembly.
This regex expression should do what you want:
[[:digit:]]{3}
This regex expression should do what you want:
[[:digit:]]{3}
I suspect that would accept a value of "0".
*ERROR* with results I don't wish to contemplate.
On 02.07.2024 17:00, candycanearter07 wrote:
Richard Owlett <[email protected]> wrote at 14:40 this Tuesday (GMT):
I have a Debian machine with Kate Version 16.08.3 .
I wish to do a search & replace using regular expressions.
The "Help" menu has led to
https://docs.kde.org/stable5/en/kate/katepart/regular-expressions.html
and
https://docs.kde.org/stable5/en/kate/katepart/regex-patterns.html
I have strings of the form "XYZn" where n is one to three digits
representing values of from 1 to 299. I wish to replace all occurrences
with "abc".
The documents give essentially no examples.
Help please.
TIA
I'd recommend using an online regex generator like
https://regex101.com/.
This regex expression should do what you want:
[[:digit:]]{3}
Doesn't that mean _exactly_ 3 digits? (The OP wanted 1-299, which
may be one up to three digits.) Some regexp parsers allow {,3} for
an up-to range (but that might mean 0-3, thus also not the desired expression). Or you can explicitly specify the digits range {1,3}.
Janis
In article <v63bs4$25m5u$[email protected]>,
Richard Owlett <[email protected]> wrote:
...
This regex expression should do what you want:
[[:digit:]]{3}
I suspect that would accept a value of "0".
*ERROR* with results I don't wish to contemplate.
I suspect that what you want to do actually can't be done (accurately) with regexps, if we interpret your requirements literally. Most responders so
far have pretty much glossed over your requirements.
For example, while
you want to match (and replace) XYZ299, you want to leave XYZ300 alone.
You probably need a programming languages (such as AWK) to do this correctly.
Note, BTW, that the real problem with regexps is that there are so many different implementations. Supposedly, there is a standard - actually, multiple standards - but each implementation is subtly different. For example, sometimes you need \ before special characters like ( or { or ?
and sometimes you don't (depending on which implementation you are using).
On 02.07.2024 16:40, Richard Owlett wrote:
I have a Debian machine with Kate Version 16.08.3 .
Disclaimer: I don't know the Kate editor. But I know Regular
Expressions (RE).
I wish to do a search & replace using regular expressions.
The "Help" menu has led to
https://docs.kde.org/stable5/en/kate/katepart/regular-expressions.html
and
https://docs.kde.org/stable5/en/kate/katepart/regex-patterns.html
I have strings of the form "XYZn" where n is one to three digits
representing values of from 1 to 299. I wish to replace all occurrences
with "abc".
You may do that with simple patterns if you don't have, say,
strings like XYZ300 that shall be disregarded.
Then the RE
may simply be XYZ[0-9]+ meaning any string XYZ that is
followed by an arbitrary number of digits. Instead you can
specify digits as optional XYZ[0-9][0-9]?[0-9]? or define
the amount of digits (1-3) explicitly XYZ[0-9]{1,3} which
still allows numbers out of range 1..299 (say, 0, 300) or
undesired syntaxes like 00 or 000. - Not sure it matters in
your case. If it matters, you can define alternatives with
a bar-symbol, e.g., XYZ([1-9]|[1-9][0-9]|[1-2][0-9][0-9])
that you group with parenthesis.
Where you put such regular expressions in your Kate editor
is known to you, I suppose?
XYZ hello world
XYZ0 hello world
XYZ017 hello world
XYZ1 hello world
XYZ34 hello world
XYZ999 hello world
XYZ hello world
XYZ0 hello world
XYZ017 hello world
abc hello world
abc hello world
abc9 hello world
The documents give essentially no examples.
Regular expressions may first appear confusing, but the links
you posted actually has relevant examples.
Help please.
TIA
Hope that helps.
Janis
On 02.07.2024 17:00, candycanearter07 wrote:
Richard Owlett <[email protected]> wrote at 14:40 this Tuesday (GMT):
I have a Debian machine with Kate Version 16.08.3 .
I wish to do a search & replace using regular expressions.
The "Help" menu has led to
https://docs.kde.org/stable5/en/kate/katepart/regular-expressions.html
and
https://docs.kde.org/stable5/en/kate/katepart/regex-patterns.html
I have strings of the form "XYZn" where n is one to three digits
representing values of from 1 to 299. I wish to replace all occurrences
with "abc".
The documents give essentially no examples.
Help please.
TIA
I'd recommend using an online regex generator like
https://regex101.com/.
This regex expression should do what you want:
[[:digit:]]{3}
Doesn't that mean _exactly_ 3 digits? (The OP wanted 1-299, which
may be one up to three digits.) Some regexp parsers allow {,3} for
an up-to range (but that might mean 0-3, thus also not the desired expression). Or you can explicitly specify the digits range {1,3}.
Janis
On 02.07.2024 16:40, Richard Owlett wrote:
I have a Debian machine with Kate Version 16.08.3 .
Disclaimer: I don't know the Kate editor. But I know Regular
Expressions (RE).
I wish to do a search & replace using regular expressions.
The "Help" menu has led to
https://docs.kde.org/stable5/en/kate/katepart/regular-expressions.html
and
https://docs.kde.org/stable5/en/kate/katepart/regex-patterns.html
I have strings of the form "XYZn" where n is one to three digits
representing values of from 1 to 299. I wish to replace all occurrences
with "abc".
You may do that with simple patterns if you don't have, say,
strings like XYZ300 that shall be disregarded. Then the RE
may simply be XYZ[0-9]+ meaning any string XYZ that is
followed by an arbitrary number of digits. Instead you can
specify digits as optional XYZ[0-9][0-9]?[0-9]? or define
the amount of digits (1-3) explicitly XYZ[0-9]{1,3} which
still allows numbers out of range 1..299 (say, 0, 300) or
undesired syntaxes like 00 or 000. - Not sure it matters in
your case. If it matters, you can define alternatives with
a bar-symbol, e.g., XYZ([1-9]|[1-9][0-9]|[1-2][0-9][0-9])
that you group with parenthesis.
Where you put such regular expressions in your Kate editor
is known to you, I suppose?
The documents give essentially no examples.
Regular expressions may first appear confusing, but the links
you posted actually has relevant examples.
Help please.
TIA
Hope that helps.
Janis
| Sysop: | Keyop |
|---|---|
| Location: | Huddersfield, West Yorkshire, UK |
| Users: | 716 |
| Nodes: | 16 (2 / 14) |
| Uptime: | 49:34:17 |
| Calls: | 12,115 |
| Calls today: | 6 |
| Files: | 15,010 |
| Messages: | 6,518,539 |