473,394 Members | 2,002 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

regular expression to negate the start of line char '^'?

Hi
I have the following code that lists first names of people who's
surnames are 'Morris'. What I am trying to do is search for first names that
don't start at the beginning of the line ie. have the '[^\^]' in the regExp
object, but 'Neil' is matched even though it is next to(?) the start of line
char(?) or should I say 'Neil' is the first 'word' of the string?

here's the code

<html>
<head>
<title>
my RegExp
</title>
</head>
<body>
<script>
var myPat = new RegExp("([^\\^]\\w+) Morris","gi");
var str = new String("Neil Morris Lee Morris Jenny Morris Jackie Morris mai
Morris wong Morris write Morris");
var count=1;
while(myArray=myPat.exec(str)) {
for(i=1;i<myArray.length;i++) {
document.write(+count+"=array\["+i+"\] \""+myArray[i]+"\"<br>");
}
document.write("RegExp objects methods and results<br>");
document.write("myPat.lastIndex="+myPat.lastIndex+ "<br>");
document.write("myPat.source="+myPat.source+"<br>" );
document.write("array from RegExp object exec method<br>");
document.write("method index="+myArray.index+"<br>");
document.write("method input="+myArray.input+"<br>");
document.write("method \[0\]=#"+myArray[0]+"<br>");
document.write("string before
match=#"+myArray.input.substring(0,myArray.index)+ "#<br>");
document.write("string after
match=#"+myArray.input.substring(myArray.index+myA rray[0].length)+"#<br>");
document.write("<hr>");

count++;
}
</script>
</body>
</html>
--
my IE6 favorites (bookmarks URL's)
http://www.myjavaware.co.uk/bookmark.htm
Jul 20 '05 #1
1 8212
"Neil Morris" <Ne********@btinternet.com> writes:
I have the following code that lists first names of people who's
surnames are 'Morris'. What I am trying to do is search for first names that
don't start at the beginning of the line ie. have the '[^\^]' in the regExp
object,
That regular expression matches the character "^", and only that.
but 'Neil' is matched even though it is next to(?) the start of line
char(?) or should I say 'Neil' is the first 'word' of the string?


If you want to check that something is not at the beginning of the line,
just check that something occurs before it. Perhaps even check that
something non-whitespace occurs before it:

/\S\s+Morris/

(something non-whitespace followed by one or more whitespace followed by
"Morris")
/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

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

Similar topics

1
by: Kenneth McDonald | last post by:
I'm working on the 0.8 release of my 'rex' module, and would appreciate feedback, suggestions, and criticism as I work towards finalizing the API and feature sets. rex is a module intended to make...
3
by: Tom | last post by:
I have struggled with the issue of whether or not to use Regular Expressions for a long time now, and after implementing many text manipulating solutions both ways, I've found that writing...
0
by: Dave | last post by:
I need to find a way to do a replace based on the following logic: Any substring which: 1) begins with "/" a) but not "{/" 2) is not followed by any of the following strings "cf" "line" 3)...
2
by: Brian Kitt | last post by:
I have a process where I do some minimal reformating on a TAB delimited document to prepare for DTS load. This process has been running fine, but I recently made a change. I have a Full Text...
3
by: Zach | last post by:
Hello, Please forgive if this is not the most appropriate newsgroup for this question. Unfortunately I didn't find a newsgroup specific to regular expressions. I have the following regular...
25
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...
11
by: Steve | last post by:
Hi All, I'm having a tough time converting the following regex.compile patterns into the new re.compile format. There is also a differences in the regsub.sub() vs. re.sub() Could anyone lend...
8
by: Summercool | last post by:
somebody who is a regular expression guru... how do you negate a word and grep for all words that is tire but not snow tire or
1
by: AAaron123 | last post by:
I found this on the Internet and tried a few of them and they worked in VS2008. Actually it was in a different form but I converted to make a smaller file. The data is the same as the original. ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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...

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.