Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 679177
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:13:52+00:00 2026-05-14T01:13:52+00:00

This was a fascinating debugging experience. Can you spot the difference between the following

  • 0

This was a fascinating debugging experience.
Can you spot the difference between the following two lines?

StringReplace["–", RegularExpression@"[\\s\\S]" -> "abc"]
StringReplace["-", RegularExpression@"[\\s\\S]" -> "abc"]

They do very different things when you evaluate them. It turns out it’s because the string being replaced in the first line consists of a unicode en dash, as opposed to a plain old ascii dash in the second line.

In the case of the unicode string, the regular expression doesn’t match.
I meant the regex “[\s\S]” to mean “match any character (including newline)” but Mathematica apparently treats it as “match any ascii character”.

How can I fix the regular expression so the first line above evaluates the same as the second? Alternatively, is there an asciify filter I can apply to the strings first?

PS: The Mathematica documentation says that its string pattern matching is built on top of the Perl-Compatible Regular Expressions library (http://pcre.org) so the problem I’m having may not be specific to Mathematica.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T01:13:52+00:00Added an answer on May 14, 2026 at 1:13 am

    Here’s an asciify function which I used as a workaround at first:

    f[s_String] := s
    f[x_] := FromCharacterCode[x]
    
    asciify[s_String] := 
      StringJoin[f /@ (ToCharacterCode[s] /. x_?(#>255&) :> "&"<>ToString[x]<>";")]
    

    Then I realized, thanks to @Isaac’s answer, that “.” as a regular expression doesn’t seem to have this unicode problem. I learned from the answers to Bug in Mathematica: regular expression applied to very long string that “(.|\n)” is ill-advised but that “(?s).” is recommended. So I think the best fix is the following:

    StringReplace["–", RegularExpression@"(?s)." -> "abc"]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After coming up against this problem myself in trying to implement a generic Vector2<int/float/double>
Got stuck while trying to make an element in website behave like this: <div
I looked at several related answers, and determined that I can programmatically clear the
this is the code for my custom provider, mostly copied from the SDK notepad
This is from Sun's tutorial's exercise area so I suppose it is homework. I
This question is because normally when you want to click a button or link
I just started taking a class on C# .NET and have found it really
Q: Where to start for understanding databases internals? And developing a (simple) database? Note:
I was just answering a question about different approaches for picking the partition in
A question regarding a parser. Is there any chance to catch some separators within

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.