thus if i wanted to match anything but "delete" in "deleteaddress" i would match address
This is all i have
Code: Select all
/[^(delete)]/Moderator: General Moderators
Code: Select all
/[^(delete)]/Code: Select all
/(.*)delete(.*)/NOT QUITE....this will match delete and not address I need it to match address an NOT delete thus a ('delete_address').replace() would give me "delete" and NOT "address"AbraCadaver wrote:The [ and ] contain character classes. You can't use it that way. Here is something that may work:
Code: Select all
/(.*)delete(.*)/
Code: Select all
[^delete](.*)Code: Select all
('deleteevents').replace(/[^delete](.*)/,"")Code: Select all
var reg = /([^delete].*)/Code: Select all
/((?<!delete|add|edit|rename).*)/I get some kind of error when i add the ">"AbraCadaver wrote:OK, that's more information. You need a negative lookbehind. Something like this might work:
Code: Select all
/((?<!delete|add|edit|rename).*)/
Actually, this regex does not behave like you think. The negative lookbehind is asserted only once at the beginning of the test string (which will always be true), but is never checked again. The dot star then happily marches though the entire string matching everything in its wake. This regex matches every string in the universe! And as it turns out, kendall is using JavaScript which doesn't have lookbehind...AbraCadaver wrote:OK, that's more information. You need a negative lookbehind. Something like this might work:
Code: Select all
/((?<!delete|add|edit|rename).*)/
You are using JavaScript yes? Unfortunately the JavaScript regex engine does not handle negative or positive lookbehind syntax - i.e. neither (?<!...) nor (?<=...) However, JavaScript does handle both positive and negative lookahead syntax. But this is not what you need here...kendall wrote:... I get some kind of error when i add the ">" ...
What do you want to replace it with?kendall wrote:... I want to replace anything that is NOT "delete|add|edit|rename" at the beginning of the string
Code: Select all
// regex to capture the initial keyword in group 1 and the rest in group 2
var RE = /^(delete|add|edit|rename)(.*)/mg;
// if you want to keep the keyword and discard the rest, use this
var result = 'deleteevent'.replace(RE, "$1"); // 'delete'
// if you want to discard the keyword and keep the rest, use this
var result = 'deleteevent'.replace(RE, "$2"); // 'event'