regular expression all string but not '.dwg'

X

xlstatik

Hallo,

ist ist possible to search with regexp for all extensions wihtout the
single exception '.dwg'?
Who would this regular expression look like?
 
O

Oliver Wong

xlstatik said:
Hallo,

ist ist possible to search with regexp for all extensions wihtout the
single exception '.dwg'?
Who would this regular expression look like?

Technically, a regular expression will either accept a given input
string, or reject it. It does not do searching in and of itself.

When searching with a regular expression is done, what usually happens
is that a whole bunch of substrings of the so-called "haystack string" are
passed over to the regular expression, and the longest such substring is
returned as the so-called "needle string". The details in the implementation
will alter the behaviour of the program. So for example, you could say "Give
me all non-overlapping substrings of parameter1 which do not contain
'.dwg'", and then pass ".dwg" as parameter1, and the search engine will
return two substrings: {".dw", "g"}, both fo which don't contain ".dwg".

In other words, you'll have to be more specific in your description of
what you want. Do any of these boolean expressions do what you want?

!inputString.endsWith(".dwg")
!inputString.contains(".dwg")
!inputString.equals(".dwg")

- Oliver
 
S

shakah

xlstatik said:
Hallo,

ist ist possible to search with regexp for all extensions wihtout the
single exception '.dwg'?
Who would this regular expression look like?

If all the things you are comparing have extensions, and they are all
three letters, something like the following might work for you:
"^.*\.([^d]..|.[^w].|..[^g])$"
 
Joined
Jul 9, 2023
Messages
1
Reaction score
0
To match all strings except for '.dwg', you can use a negative lookahead in your regular expression. Here's an example of how you can do it:
regexCopy code
^(?!.\.dwg$).$
Explanation of the regular expression:
  • ^ asserts the start of the string.
  • (?!.*\.dwg$) is a negative lookahead that checks if the string is not followed by '.dwg' at the end.
    • (?!...) is a negative lookahead assertion.
    • .* matches any characters (except newline) zero or more times.
    • \.dwg matches the literal string '.dwg'. The backslash \ is used to escape the dot, as it has a special meaning in regex.
    • $ asserts the end of the string.
  • .* matches any characters (except newline) zero or more times.
  • $ asserts the end of the string.
This regular expression will match any string except for '.dwg' at the end.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,268
Latest member
AshliMacin

Latest Threads

Top