This content has been marked as final. Show 6 replies
GREP is case-sensitive, so "sin" doesn't find anything in "SG SIN Singapore". To search case-insensitively and whole words only, use (?i)\bsin\b
But your question isn't entirely clear. You start by asking "How do you get grep to return a single line even when multiple matches are found on the same line?", then you say "I don't want the search to stop after a single match, it should continue on successive lines". These two seem to contradich each other. Do you mean you want one match per line?
Sorry for the unclear description.
I would like to get 1 match per line, and have grep return the whole line.
so a case insensitive search of
MY KUL Kuala Lumpar
SG SIN Singapore
ID JKT Jakarata
searching for "sin" would return the whole line "SG SIN Singapore" a single time.
Is that possible ?
Sure. Let GREP find an entire line at once:<br /><br />>^.*sin.*$<br /><br />But it won't work, I'm afraid. You insist that looking for "sin" <br />i will find <br />a match in "SG SIN Singapore"; and not one but two. It won't. Try it.<br /><br /><pre> __<br />(..)<br /> _\</pre><br />Got that? So use the 'case insensitive' switch<br /><br />>(?i)^.*sin.*$<br /><br />or (perhaps better, in this case), as you seem to search for the three letter codes, use<br /><br />>^.*\<SIN\>.*$
Thanks, that seems to work.
Is there a way tell grep to stop after the first match?
How do you want to 'stop' grep? In JS, calling
returns immediately, with the result of the search. That result is an array of found items, and the number of items indicate the number of occurrences found (0, 1, or more). There is nothing to stop.
use just the first found match of the results array in your script (I presume you need it for a certain 'use').
it seems needn't Grep.stop it likely simple,for(gerp) when mached display a form.