Skip to main content

Timeline for Apex regex and non-capturing groups

Current License: CC BY-SA 3.0

13 events
when toggle format what by license comment
Aug 6, 2016 at 20:44 vote accept Grisk
Aug 6, 2016 at 20:44 vote accept Grisk
Aug 6, 2016 at 20:44
Aug 6, 2016 at 20:44 vote accept Grisk
Aug 6, 2016 at 20:44
Aug 4, 2016 at 23:07 history tweeted twitter.com/StackSalesforce/status/761337732589359104
Aug 4, 2016 at 21:09 answer added Mark Pond timeline score: 2
Aug 4, 2016 at 19:02 answer added Grisk timeline score: 3
Aug 4, 2016 at 18:55 history edited Adrian Larson CC BY-SA 3.0
added 40 characters in body
Aug 4, 2016 at 18:17 comment added Grisk No worries! Check out the demo I linked to, the "(\d+)" bit is where I'm capturing the number. The simpler example that I gave inline just shows the Salesforce parser failing when I have two noncapture groups, but that isn't the same as the "real" regex that I linked to. As to the efficiency quesiton, I don't think so, but I could be wrong. The * itself indicates zero or more, so the ? added at the end is redundant, I think. I'll have to read more about that one.
Aug 4, 2016 at 18:15 comment added dBeltowski Also maybe not so relevant to the question, but wouldn't the regex be more efficient like this? ^(?:.*?)(?:{"id":)$
Aug 4, 2016 at 18:14 comment added dBeltowski Are you trying to get the id value 11111? My regex is a tad rusty but I don't see you actually capturing any information. Also with the $ indicating the end of the string wouldn't the regex you provided stop before getting to the 11111?
Aug 4, 2016 at 17:54 comment added Grisk TLDR: yes. This object is coming back from a REST API that is fairly unstable. They are still updating it constantly, and it currently contains a massive number of different fields that I can't prevent the query from returning. All I need is the ID, and I thought that writing a regular expression for this would be fairly straightforward 😅 Since this code has to run quite often, I wanted to avoid the overhead of serializing massive objects that will need to be constantly updated in step with the external service.
Aug 4, 2016 at 17:52 comment added Mark Pond Any particular reason you want to use regex instead of deserializing into a concrete type or map structure?
Aug 4, 2016 at 17:43 history asked Grisk CC BY-SA 3.0