RegEx in JS question

33 views
Skip to first unread message

Ted Stresen-Reuter

unread,
Feb 23, 2021, 4:44:01 PM2/23/21
to bbe...@googlegroups.com
Hi list 👋

I'm trying to do some advanced parsing of source code using RegEx. I'm using non-capturing parentheses "(?…)" and friends for look aheads and look behinds and such. I'm wondering if anyone can tell me:

1. What type of RegEx extension are these types of patterns (look aheads, look behinds)?
2. Is there an equivalent that could be used in JavaScript, say, in a node application?

Thanks in advance and keep safe in these difficult times.

Ted Stresen-Reuter

MediaMouth

unread,
Feb 24, 2021, 12:37:09 AM2/24/21
to BBEdit Talk
Re non-capturing parentheses, this might help: https://stackoverflow.com/questions/3512471/what-is-a-non-capturing-group-in-regular-expressions

For the most part RegEx in JS & BBEdit are much the same.  The big difference is that in JS vs BBEdit is the syntax for the backreference.
(\ (backslash) in BBEdit vs $ in JS)

So for example say your Find is "AE" plus a 3rd uppercase character [A-Z], followed by a number [0-9], where you want to inserted new text between the letters and numbers...

In BBEdit that would be Find: (AE[A-Z])([0-9])  Replace: \1InsertedNewText\2  
In JS the same thing is: SomeText.replace(/(AE[A-Z])([0-9])/g, $1InsertedNewText$2);

jj

unread,
Feb 24, 2021, 2:57:50 AM2/24/21
to BBEdit Talk
Hi Ted,

BBEdit regular expressions are based on PCRE2 (see credits in 'BBEdit about').

For quick reference the BBEdit Help is excellent:  'Help menu' > BBEdit Help > Quick Reference > Grep Reference.
For the definitive documentation on PCRE: https://www.pcre.org/current/doc/html/pcre2syntax.html

You can also test and compare your regular expressions in this excellent playground : https://regex101.com

Best regards,

Jean Jourdain

Ted Stresen-Reuter

unread,
Feb 24, 2021, 3:22:06 AM2/24/21
to bbe...@googlegroups.com
All excellent pointers. Thank you all. I have to assume I can use lookahead and lookbehind assertions in JavaScript, either natively or via a node library, but wasn't sure how to phrase the question to begin with.

Kind regards,

Ted

--
This is the BBEdit Talk public discussion group. If you have a feature request or need technical support, please email "sup...@barebones.com" rather than posting here. Follow @bbedit on Twitter: <https://twitter.com/bbedit>
---
You received this message because you are subscribed to the Google Groups "BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bbedit+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bbedit/f5e5f412-27c5-405d-ba8c-5067319e0221n%40googlegroups.com.

Patrick Woolsey

unread,
Feb 24, 2021, 9:52:59 AM2/24/21
to bbe...@googlegroups.com
On 2/24/21 at 3:21 AM, tedmas...@gmail.com (Ted
Stresen-Reuter) wrote:

>All excellent pointers. Thank you all. I have to assume I can use lookahead
>and lookbehind assertions in JavaScript, either natively or via a node
>library, but wasn't sure how to phrase the question to begin with.

In general that is a reasonable assumption. :-)
I second Jean's recommendation above :-) and please note the
Mozilla guide also covers browser compatibility:

<https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#browser_compatibility>


Regards

Patrick Woolsey
==
Bare Bones Software, Inc. <https://www.barebones.com/>

Dave

unread,
Feb 24, 2021, 5:05:01 PM2/24/21
to BBEdit Talk

Lookahead, yes. Lookbehind, no.
Reply all
Reply to author
Forward
0 new messages