473,804 Members | 2,133 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do I write a reg expression to search for NOT a substring?

I want a regular expression that will return TRUE if there is NOT a
substring in the string. Example: Return true if the substring "image" is
NOT in the string.

TIA,

Larry Woods
Jul 20 '05 #1
2 1982
"Larry Woods" <la***@lwoods.c om> writes:
I want a regular expression that will return TRUE if there is NOT a
substring in the string. Example: Return true if the substring "image" is
NOT in the string.


That is hard.

It is much easier to return true if the search string is in the string
to be searched. Then use negation to return the opposite:

!(/image/).test(myStr)

If you really insist on a regular expression that matches all strings
without the substring "image", then here are some suggestions:

Using lookahead:
/^((?!image).)*$/
(probably horribly inefficient with all that lookahead)

Brute force:
/^([^i]*)((i[^im]|i$|im[^ia]|im$|ima[^ig]|ima$|imag[^ie]|imag$)[^i]*)*$/

Combination, only do lookahead on an i.
/^([^i]*)((i(?!mage))*[^i]*)*$/

Enjoy
/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #2
Lookahead works great!
Using lookahead:
/^((?!image).)*$/
(probably horribly inefficient with all that lookahead)
I am using it in a vb.net application any it's "instantaneous! " (600 record
file)

Thanks.

Larry

"Lasse Reichstein Nielsen" <lr*@hotpop.com > wrote in message
news:y8******** **@hotpop.com.. . "Larry Woods" <la***@lwoods.c om> writes:
I want a regular expression that will return TRUE if there is NOT a
substring in the string. Example: Return true if the substring "image" is NOT in the string.


That is hard.

It is much easier to return true if the search string is in the string
to be searched. Then use negation to return the opposite:

!(/image/).test(myStr)

If you really insist on a regular expression that matches all strings
without the substring "image", then here are some suggestions:

Using lookahead:
/^((?!image).)*$/
(probably horribly inefficient with all that lookahead)

Brute force:
/^([^i]*)((i[^im]|i$|im[^ia]|im$|ima[^ig]|ima$|imag[^ie]|imag$)[^i]*)*$/

Combination, only do lookahead on an i.
/^([^i]*)((i(?!mage))*[^i]*)*$/

Enjoy
/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
'Faith without judgement merely degrades the spirit divine.'

Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2525
by: Ike | last post by:
Can anyone discern why the following code writes the document.write() lines literally? That is, a line like document.write('<CENTER>') should write <CENTER> but instead writes the entire document.write('<CENTER>'). I must be really doing something stupid. Can anyone here illuminate me? Thanks, Ike <HTML><HEAD> <TITLE>My Applet</TITLE> </HEAD><BODY>
7
9024
by: Scott | last post by:
I need help to modify the code below to pass url variables from a framset. The click to run this will be in the mainFrame. This script works well in a non-frame page. Grabs the current url variables and adds them to my url. <script type="text/javascript"> //<!]> </script>
6
2438
by: dreamerbin | last post by:
Hi, I'm having trouble extracting substrings using regular expression. Here is my problem: Want to find the substring that is immediately before a given substring. For example: from "00 noise1 01 noise2 00 target 01 target_mark", want to get "00 target 01"
8
3395
by: Ahmad A. Rahman | last post by:
Hi all, I have a problem constructing a regular expression using .net. I have a string, separated with comma, and I want to group the string together but, I failed to group a numeric character with decimal values. Example string : 1, 2.3, "two"," three" So, I want to group this string into 4 groups (1), (2.3), (two) and (three)
10
3041
by: Lee Kuhn | last post by:
I am trying the create a regular expression that will essentially match characters in the middle of a fixed-length string. The string may be any characters, but will always be the same length. In other words, as the regular expression (....)($) matches the "4567" in the string "1234567", how would I create a similar regular expression that only matches the "45" in the same string. The same regular expression would match "32" in the string...
11
5363
by: Darren Anderson | last post by:
I have a function that I've tried using in an if then statement and I've found that no matter how much reworking I do with the code, the expected result is incorrect. the code: If Not (strIn.Substring(410, 10).Trim = "") Then 'Something processed Else 'Something processed
7
3279
by: Kevin CH | last post by:
Hi, I'm currently running into a confusion on regex and hopefully you guys can clear it up for me. Suppose I have a regular expression (0|(1(01*0)*1))* and two test strings: 110_1011101_ and _101101_1. (The underscores are not part of the string. They are added to show that both string has a substring that matches the pattern.) Applying a match() function on the first string returns true while false for the second. The difference...
25
5178
by: Mike | last post by:
I have a regular expression (^(.+)(?=\s*).*\1 ) that results in matches. I would like to get what the actual regular expression is. In other words, when I apply ^(.+)(?=\s*).*\1 to " HEART (CONDUCTION DEFECT) 37.33/2 HEART (CONDUCTION DEFECT) WITH CATHETER 37.34/2 " the expression is "HEART (CONDUCTION DEFECT)". How do I gain access to the expression (not the matches) at runtime? Thanks, Mike
4
1618
by: sowen | last post by:
hi, folks I am doing a automate tool to remove a project reference from the VS.NET solution file. Suppose the sln file has this project definition Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Project", "..\.. \..\Project.csproj", "{9D8A6B4A-8B37-4C2E-80B9-0DA4C5EF33B1}"
0
9715
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9595
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10353
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10356
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10099
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7643
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5536
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3836
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3003
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.