Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RegExp has no convenient way to see if a substring starts with a match to RegExp #166

Closed
rakudrama opened this issue Oct 18, 2011 · 3 comments
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. type-enhancement A request for a change that isn't a bug

Comments

@rakudrama
Copy link
Member

RegExp re = ...

I want to say something like
Match m = re.matchAt(str, pos);
or
String s = re.matchStringAt(str, pos);

The match should be tethered to the given position, i.e. succeed only if str[pos ... end) matches the re.

Currently all the RegExp methods do a search and none do a simple match. It is inconvenient to have to specify regexps with a leading ^ and there is no convenient way to convert a RegExp without a leading ^ into one with.

None of search methods allow a search in a substring. This would be OK if string.substring was guaranteed constant time + space, but the documentation on String.substring makes no claims.

@rakudrama
Copy link
Member Author

Removed the owner.
Removed Type-Defect label.
Added Type-Enhancement, New labels.

@DartBot
Copy link

DartBot commented Oct 20, 2011

This comment was originally written by drfibonacci@google.com


Added Area-Library, Triaged labels.

@lrhn
Copy link
Member

lrhn commented Jun 13, 2013

I've added a method to Pattern called matchAsPrefix which also takes an optional start position. That means you can do:
  Match m = re.matchAsPrefix(str, pos);
and get what you want.

Fair warning: It's still not efficient on the VM where it just does a search and checks if the start of a match is pos. I hope we'll eventually get a RegExp implementation that's more efficient, or maybe use the same hack that is used for JS RegExps.

You can create a modified RegExp by using the pattern and flags of the original.
  var re = ...some regexp ...
  var anchorRe = new RegExp("^(?:${re.pattern})", multiline: re.iSMultiline,
                                                  caseSenitive: re.isCaseSensitive);

Prefixing with "^" wouldn't work though - it only matches the start of the string, which is never at a position > 0. What we do for JS RegExp is to suffix with "|()", so there is a guaranteed zero-length match at the start position if the original regexp didn't match. This prevents searching, and allows us to recognize that the original regexp didn't match if the extra capture participated.


Added Fixed label.

@rakudrama rakudrama added Type-Enhancement area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. labels Jun 13, 2013
@kevmoo kevmoo added type-enhancement A request for a change that isn't a bug and removed type-enhancement labels Mar 1, 2016
copybara-service bot pushed a commit that referenced this issue Feb 6, 2023
…ev, boolean_selector_rev, browser_launcher_rev, characters_rev, cli_util_rev, clock_rev, collection_rev, convert_rev, crypto_rev, csslib_rev

Revisions updated by `dart tools/rev_sdk_deps.dart`.

args (https://github.com/dart-lang/args/compare/a23ea85..bd3ac85):
  bd3ac85  2023-02-01  dependabot[bot]  Bump dart-lang/setup-dart from 1.3 to 1.4 (#234)
  86dacb3  2023-02-01  dependabot[bot]  Bump actions/checkout from 3.2.0 to 3.3.0 (#233)

async (https://github.com/dart-lang/async/compare/f700e9a..8deaa40):
  8deaa40  2023-02-01  dependabot[bot]  Bump actions/checkout from 3.2.0 to 3.3.0 (#234)
  b28604f  2023-02-01  dependabot[bot]  Bump dart-lang/setup-dart from 1.3 to 1.4 (#233)

bazel_worker (https://github.com/dart-lang/bazel_worker/compare/b35c25e..1124692):
  1124692  2023-02-01  dependabot[bot]  Bump dart-lang/setup-dart from 1.3 to 1.4 (#67)
  1e57757  2023-02-01  dependabot[bot]  Bump actions/checkout from 3.2.0 to 3.3.0 (#68)

benchmark_harness (https://github.com/dart-lang/benchmark_harness/compare/76881df..b1efcf7):
  b1efcf7  2023-02-02  Devon Carew  add a publishing workflow action to dart-lang/benchmark_harness (#81)
  4e0c4e8  2023-02-01  dependabot[bot]  Bump actions/checkout from 3.2.0 to 3.3.0 (#83)
  010ea89  2023-02-01  dependabot[bot]  Bump dart-lang/setup-dart from 1.3 to 1.4 (#82)

boolean_selector (https://github.com/dart-lang/boolean_selector/compare/ba7d86b..16e6ad3):
  16e6ad3  2023-01-31  dependabot[bot]  Bump dart-lang/setup-dart from 1.3 to 1.4 (#42)
  c8874cc  2023-01-31  dependabot[bot]  Bump actions/checkout from 3.2.0 to 3.3.0 (#43)

browser_launcher (https://github.com/dart-lang/browser_launcher/compare/f2f01e4..bc2dc4e):
  bc2dc4e  2023-01-31  dependabot[bot]  Bump dart-lang/setup-dart from 1.3 to 1.4 (#38)
  00a57fa  2023-01-31  dependabot[bot]  Bump actions/checkout from 3.2.0 to 3.3.0 (#39)

characters (https://github.com/dart-lang/characters/compare/4526aa8..29f3a3e):
  29f3a3e  2023-02-01  dependabot[bot]  Bump actions/checkout from 3.2.0 to 3.3.0 (#73)
  6516030  2023-02-01  dependabot[bot]  Bump dart-lang/setup-dart from 1.3 to 1.4 (#74)

cli_util (https://github.com/dart-lang/cli_util/compare/32bc077..fd38b5f):
  fd38b5f  2023-01-31  dependabot[bot]  Bump actions/checkout from 3.2.0 to 3.3.0 (#74)
  166fbac  2023-01-31  dependabot[bot]  Bump dart-lang/setup-dart from 1.3 to 1.4 (#75)

clock (https://github.com/dart-lang/clock/compare/65e8a13..5abb481):
  5abb481  2023-02-01  dependabot[bot]  Bump actions/checkout from 3.2.0 to 3.3.0 (#43)
  11b18ed  2023-02-01  dependabot[bot]  Bump dart-lang/setup-dart from 1.3 to 1.4 (#44)

collection (https://github.com/dart-lang/collection/compare/a566328..0d0e184):
  0d0e184  2023-02-01  dependabot[bot]  Bump dart-lang/setup-dart from 1.3 to 1.4 (#268)
  d0897af  2023-02-01  dependabot[bot]  Bump actions/checkout from 3.2.0 to 3.3.0 (#269)

convert (https://github.com/dart-lang/convert/compare/20d136c..83886e3):
  83886e3  2023-02-01  dependabot[bot]  Bump actions/checkout from 3.2.0 to 3.3.0 (#75)
  a522506  2023-01-31  dependabot[bot]  Bump dart-lang/setup-dart from 1.3 to 1.4 (#74)

crypto (https://github.com/dart-lang/crypto/compare/f854f2f..03eb2c9):
  03eb2c9  2023-01-31  dependabot[bot]  Bump actions/checkout from 3.2.0 to 3.3.0 (#139)
  b6d6b33  2023-01-31  dependabot[bot]  Bump dart-lang/setup-dart from 1.3 to 1.4 (#140)

csslib (https://github.com/dart-lang/csslib/compare/f33d632..e6c8308):
  e6c8308  2023-01-31  Devon Carew  fix the reported span for expressions (#167)
  a190358  2023-01-31  Devon Carew  add a repro for #136 (#160)
  fa3e221  2023-01-31  Devon Carew  correct the logic in isPredefinedName (#166)

Change-Id: I68bc236d4e0b5c31b5d629f2b89f82f56d30a28e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/281260
Auto-Submit: Devon Carew <devoncarew@google.com>
Commit-Queue: Nate Bosch <nbosch@google.com>
Reviewed-by: Nate Bosch <nbosch@google.com>
copybara-service bot pushed a commit that referenced this issue Sep 12, 2023
Revisions updated by `dart tools/rev_sdk_deps.dart`.

dartdoc (https://github.com/dart-lang/dartdoc/compare/f5750f5..dd28f4c):
  dd28f4ce  2023-09-11  dependabot[bot]  Bump actions/cache from 3.3.1 to 3.3.2 (#3497)
  2ac7e323  2023-09-11  dependabot[bot]  Bump actions/upload-artifact from 3.1.2 to 3.1.3 (#3496)

ecosystem (https://github.com/dart-lang/ecosystem/compare/2e6c3ec..e96fbdb):
  e96fbdb  2023-09-12  Moritz  Try a fix for the health check socket issues (#164)
  4cc5005  2023-09-11  Alexander Thomas  Add missing license header to license.dart (#166)
  3fbab6c  2023-09-10  Moritz  Fix boolean condition in `publish.yaml` (#163)

http (https://github.com/dart-lang/http/compare/7fb6fd6..de19214):
  de19214  2023-09-12  Sam Rawlins  Avoid passing a nullable value to Completer<nn-type>.complete (#1015)

native (https://github.com/dart-lang/native/compare/a2dfedc..5177659):
  5177659  2023-09-12  Daco Harkes  [native_assets_builder] Speedup builds for 0 or 1 packages with native assets (#129)
  7f30f4b  2023-09-12  Daco Harkes  [native_assets_builder] Take packageLayout for build and dryRun (#127)
  a7cd31e  2023-09-12  Daco Harkes  `PackageLayout` constructor for already parsed `PackageConfig` (#126)
  9f24b64  2023-09-11  Daco Harkes  [native_toolchain_c] Fix MSVC x86 toolchain resolution (#124)
  07e1de5  2023-09-06  Daco Harkes  Reenable example on CI + roll dep (#122)
  387f894  2023-09-06  Gabriel Terwesten  [native_toolchain_c] Default handling for PIC/PIE compiler flags (#121)
  0a4e5f8  2023-09-06  Gabriel Terwesten  Add support for defines to `CBuilder` (#120)

test (https://github.com/dart-lang/test/compare/27dcae1..6449495):
  64494959  2023-09-11  Jacob MacDonald  skip failing wasm tests (#2091)
  83ae0d9f  2023-09-07  Jacob MacDonald  Fix running browser tests that use deferred loading (#2090)

tools (https://github.com/dart-lang/tools/compare/2c8cbd6..fa01f9b):
  fa01f9b  2023-09-11  Elias Yishak  `--disable-telemetry` --> `--disable-analytics` (#145)

webdev (https://github.com/dart-lang/webdev/compare/9487a45..6b21ecf):
  6b21ecf0  2023-09-11  dependabot[bot]  Bump actions/labeler from 4.2.0 to 4.3.0 (#2177)
  78a5fece  2023-09-11  Sam Rawlins  Avoid passing a nullable value to Future<nn-type>.value or Completer<nn-type>.completer. (#2205)
  6f282432  2023-09-11  Parker Lougheed  [webdev] Hide `--null-safety` option (#2206)
  1c5a7bc7  2023-09-11  Parker Lougheed  Replace deprecated lints (#2208)
  f0656b4a  2023-09-11  Parker Lougheed  Fix a few minor spelling mistakes (#2209)
  158223b2  2023-09-11  Parker Lougheed  Update old dartlang.org links to new .dev equivalents (#2210)
  a8d114c5  2023-09-11  Elliott Brooks  Update the comment for lookupResolvedPackageUris
  76e050c6  2023-09-11  Elliott Brooks  Clear the map of relative URIs on DartUri.clear()
  38a17ced  2023-09-11  dependabot[bot]  Bump dart-lang/setup-dart from 1.3.0 to 1.5.0 (#2212)
  cca9e56d  2023-09-11  Elliott Brooks  Reset Webdev after release (#2227)
  824dcef7  2023-09-11  Elliott Brooks  Reset DWDS after release (#2225)
  45c09a80  2023-09-08  Elliott Brooks  Prepare Webdev for release to 3.0.8 (#2224)
  805d3b7e  2023-09-08  dependabot[bot]  Bump actions/cache from 3.2.2 to 3.3.2 (#2223)
  85d4e760  2023-09-08  Elliott Brooks  Prepare DWDS for release to version 21.0.0 (#2221)
  a3757f06  2023-09-08  Anna Gringauze  Run monorepo generate (#2222)
  c991e85a  2023-09-07  dependabot[bot]  Bump actions/checkout from 3.2.0 to 4.0.0 (#2219)
  9851c23c  2023-09-07  Parker Lougheed  Update SDK constraints for Dart 3.0 and 3.1 stable releases (#2207)

Change-Id: I0caf74af171916d30eb8ee2ab78c15acaebaa229
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/325560
Auto-Submit: Devon Carew <devoncarew@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Devon Carew <devoncarew@google.com>
copybara-service bot pushed a commit that referenced this issue Oct 31, 2023
Revisions updated by `dart tools/rev_sdk_deps.dart`.

lints (https://github.com/dart-lang/lints/compare/2cf8403..5c60f48):
  5c60f48  2023-10-30  Michael Goderbauer  Update README.md to use new syntax for adding dev dependencies (#167)

mockito (https://github.com/dart-lang/mockito/compare/4edf86f..b7d752e):
  b7d752e  2023-10-26  Ilya Yanok  Use Dart SDK 3.1.0 for format check
  ca537db  2023-10-26  Ilya Yanok  Remove unneeded deprecation warning disable comment
  1a0d0e7  2023-10-26  Ilya Yanok  Remove deprecated `returnNullOnMissingStub` and `OnMissingStub.returnNull`

native (https://github.com/dart-lang/native/compare/757f503..279094d):
  279094d  2023-10-30  Pierrick Bouvier  [native_toolchain_c] Support MSVC arm64 toolchain (#167)
  9629a55  2023-10-27  Parker Lougheed  Allow modification of a BuildOutput's raw dependencies (#169)
  762b4da  2023-10-27  Ryan Macnak  [native_assets_cli] Add Android RISCV64 target. (#166)
  18bff8c  2023-10-25  Ryan Macnak  [native_toolchain_c] Setup Linux X64 toolchain for non-X64 hosts. (#164)
  d79a7cd  2023-10-25  Ryan Macnak  [native_toolchain_c] Setup Linux RISCV64 toolchain. (#163)
  ce26f75  2023-10-25  Parker Lougheed  Update all lints and dart_flutter_team_lints dependencies (#161)

protobuf (https://github.com/dart-lang/protobuf/compare/3528fad..3f567b2):
  3f567b2  2023-10-27  Ömer Sinan Ağacan  Remove the dynamic call in `CodedBufferWriter` (#895)
  42436cd  2023-10-26  Ömer Sinan Ağacan  Keep a `ByteData` around in `CodedBufferReader` to avoid repeated `ByteData` allocs (#890)
  9a73936  2023-10-26  Ömer Sinan Ağacan  Avoid adding empty splices in `CodedBufferWriter` (#886)
  23dffde  2023-10-26  Ömer Sinan Ağacan  Update a bug link in a comment (#892)
  19903f0  2023-10-26  Ömer Sinan Ağacan  Make `CodedBufferWriter.writeRawByte` argument type more accurate (#891)
  2ce3e14  2023-10-26  Ömer Sinan Ağacan  Update `FieldInfo._ensureRepeatedField` return type (#893)
  e146515  2023-10-25  Ömer Sinan Ağacan  Avoid redundant ByteData allocation when decoding sfixed64 (#889)
  1b1d549  2023-10-25  Ömer Sinan Ağacan  Avoid allocating temporary views in when decoding strings in `CodedBufferReader` (#888)

tools (https://github.com/dart-lang/tools/compare/da6bb18..e828d45):
  e828d45  2023-10-27  Elias Yishak  Create tests for each event constructor (#186)

webdev (https://github.com/dart-lang/webdev/compare/25f17cd..50534a1):
  50534a12  2023-10-30  Elliott Brooks  Cider passes an app ID instead of a workspace name to connect to the Dart Debug Extension (#2272)
  b3d6ef14  2023-10-27  Elliott Brooks  Expose a keyboard shortcut to copy the Dart app ID (#2271)
  c26b4e5f  2023-10-27  Elliott Brooks  Reset Webdev to 3.3.0-wip after release (#2269)
  982b955b  2023-10-26  Elliott Brooks  Prepare webdev for 3.2.0  (#2268)
  62361fbf  2023-10-26  Elliott Brooks  Reset DWDS after release (#2267)
  50b8ae86  2023-10-26  Elliott Brooks  Prepare DWDS for release to version 22.1.0 (#2266)

Change-Id: Ia02db3bc66bac55b637ed5e173fe5c5d50bcca52
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/332748
Auto-Submit: Devon Carew <devoncarew@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

4 participants