• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • Carey Brown
  • Stephan van Hulst
Bartenders:
  • Frits Walraven
  • fred rosenberger
  • salvin francis

How to reformat a Javascript Regex to java

 
Greenhorn
Posts: 22
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello everyone I have made following regex and code in Javascript.


How do I reformat it to Java?





this is my atempt:



Thank you in advance
 
Saloon Keeper
Posts: 8273
71
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The first '$' means match the end of the string. If you put this anywhere other than the last character  of the regex it won't work. If you want to match a literal dollar sign you must escape it by preceding it with a backslash.
Similarly '^' matches the beginning of the string.
 
Carey Brown
Saloon Keeper
Posts: 8273
71
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In Java String literals the backslash has a special meaning, e.g. '\n' means a new-line. If you want an actual backslash character you must escape it with  a backslash, e.g. "\\d".
 
Xsi jadu
Greenhorn
Posts: 22
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Carey Brown wrote:The first '$' means match the end of the string. If you put this anywhere other than the last character  of the regex it won't work. If you want to match a literal dollar sign you must escape it by preceding it with a backslash.
Similarly '^' matches the beginning of the string.



this answer wasnt  not really helpful to me unfortunately.
 
Xsi jadu
Greenhorn
Posts: 22
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Solved it myself.


Thank you in anyway

 
Saloon Keeper
Posts: 13067
281
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Note that your regex will find two occurrences in the string "score‑board**score‑board", while it will find only one occurrence in the string "score‑board*score‑board".
 
Xsi jadu
Greenhorn
Posts: 22
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:Note that your regex will find two occurrences in the string "score‑board**score‑board", while it will find only one occurrence in the string "score‑board*score‑board".



Can you explain again please.

Thank you
 
Stephan van Hulst
Saloon Keeper
Posts: 13067
281
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In the input string that contains the two asterisks, the matcher will find "score‑board*" and it will find "*score‑board". In the input string that contains only one asterisk, it will find "score‑board*", after which the remaining input is "score‑board", which doesn't match your regular expression.

However, now that I look closer, your regular expression won't match anything at all, because you mixed your input boundary matchers; ^ means start of input, and $ means end of input.

Maybe you can explain to us what your input represents, and what information you're trying to get out of it using a regular expression.
 
There's a hole in the bucket, dear Liza, dear Liza, a hole in the bucket, dear liza, a tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic