From: stevewy on
I'm just trying to work out (if what I want is at all possible), a
regular expression that will search for and select (in a text editor
that supports regexps, like Notepad++) the word "onclick", then any
text at all, up to and including ">".

I thought

onclick*\>

would work, but it doesn't.

Basically it needs to Find the word onclick, then select all the text
up to >. Sort of like an extended search.

The wildcard "*" symbol select "the previous token", not "all and
anything" like I am used to.

What am I doing wrong?

Steve
From: Stefan Weiss on
On 10/06/10 18:14, stevewy(a)hotmail.com wrote:
> I'm just trying to work out (if what I want is at all possible), a
> regular expression that will search for and select (in a text editor
> that supports regexps, like Notepad++) the word "onclick", then any
> text at all, up to and including ">".

If the regular expressions used by Notepad++ are similar to those in
JavaScript, you could try

onclick.*?> or onclick[^>]*>

The .*? in the first variant matches anything, in a non-greedy way (as
little as possible).

The [^>]* in the second variant matches any number of characters other
than ">".

> I thought
>
> onclick*\>
>
> would work, but it doesn't.

That would match "onclic", and then a variable number of k characters.
Use "." to match any character - with the possible exception of
newlines; that depends on which modifiers are used on the regular
expression.


--
stefan
From: Joe Nine on
stevewy(a)hotmail.com wrote:
> I'm just trying to work out (if what I want is at all possible), a
> regular expression that will search for and select (in a text editor
> that supports regexps, like Notepad++) the word "onclick", then any
> text at all, up to and including ">".
>
> I thought
>
> onclick*\>
>
> would work, but it doesn't.
>
> Basically it needs to Find the word onclick, then select all the text
> up to >. Sort of like an extended search.
>
> The wildcard "*" symbol select "the previous token", not "all and
> anything" like I am used to.
>
> What am I doing wrong?
>
> Steve

I don't know the right regexp but I do notice that you're making an
assumption that the onclick is always going to be last, before the >
character. It might not be.
From: Gabriel Gilini on
Joe Nine wrote:
> stevewy(a)hotmail.com wrote:
>> I'm just trying to work out (if what I want is at all possible), a
>> regular expression that will search for and select (in a text editor
>> that supports regexps, like Notepad++) the word "onclick", then any
>> text at all, up to and including ">".
>>
>> I thought
>>
>> onclick*\>
>>
>> would work, but it doesn't.
>>
>> Basically it needs to Find the word onclick, then select all the text
>> up to >. Sort of like an extended search.
>>
>> The wildcard "*" symbol select "the previous token", not "all and
>> anything" like I am used to.
>>
>> What am I doing wrong?
>>
>> Steve
>
> I don't know the right regexp but I do notice that you're making an
> assumption that the onclick is always going to be last, before the >
> character. It might not be.
No, he isn't. Read his post again, he wants to match everything that
goes after the string "onclick" until the first appearance of ">".

What I have failed to understand is how the OP issue correlates with
Javascript.
From: Thomas 'PointedEars' Lahn on
Stefan Weiss wrote:

> stevewy(a)hotmail.com wrote:
>> I'm just trying to work out (if what I want is at all possible), a
>> regular expression that will search for and select (in a text editor
>> that supports regexps, like Notepad++) the word "onclick", then any
>> text at all, up to and including ">".
>
> If the regular expressions used by Notepad++ are similar to those in
> JavaScript, you could try
>
> onclick.*?> or onclick[^>]*>
>
> The .*? in the first variant matches anything, in a non-greedy way (as
> little as possible).
>
> The [^>]* in the second variant matches any number of characters other
> than ">".

One thing that every programmer should know is that SGML-based markup
languages like HTML, and programming languages, are usually not regular
languages (they are of the Correct Bracket Language type: context-free but
not regular), so they cannot be parsed with one regular expression alone (a
false positive for your suggestion has already been mentioned). With
further constraints as the one described here it is sometimes possible to
parse them with one application of a regular expression if the regular
expression grammar supports alternation and other special features.

The other thing is: What does this have to do with ECMAScript-based
scripting languages other than the text being replaced constitutes such
code? IMNSHO, this question is quite off-topic here, and not likely to
be answered in a way that is helpful to OP anyway, since the flavor of
regular expressions that their text editor supports is unknown.


PointedEars
--
Danny Goodman's books are out of date and teach practices that are
positively harmful for cross-browser scripting.
-- Richard Cornford, cljs, <cife6q$253$1$8300dec7(a)news.demon.co.uk> (2004)