-5

[\u0600-\u06FF\uFB8A\u067E\u0686\u06AF .!?:)(,;1234567890%-_#]+$
With the former regex, every Arabic sentence and numbers are considered mathcing.

Now the regex should match any other email addresses contained among sentences.(spaces before and after emails are not required)

What will be the regex to match?

Mehrdad Shokri
  • 1,974
  • 2
  • 29
  • 45
  • 1
    Regex is very thoroughly documented and easily located on the web, and on this site it is expected that you have done sufficient research before asking. A statement like _"I'm not really proficient in regex so I would thank you if you help me out."_ is interpreted as "I'm too lazy to do the research, please just give me an answer". It might help if you visit the [help] and read [ask] to understand what this site is about. – Jim Garrison Jun 25 '16 at 16:39
  • @Jim Garrison that shouldn't be interpreted that way, I've submitted my effort before that. The answer I'm looking for is much harder for a intermediate developer. – Mehrdad Shokri Jun 25 '16 at 16:49
  • Do you understand how your current regex is working? If yes what is stopping you from applying same logic/mechanism to pick all characters from selected range? – Pshemo Jun 25 '16 at 17:05
  • 1
    It's not clear what do you mean by "between @ and space". There's no "@" in your current regex. I think, you should re-phrase your question. My guess is you'd like to match not only arabic, but also arabic with emails in it, is that correct? – YakovL Jun 25 '16 at 17:07
  • @YakovL yes exactly. – Mehrdad Shokri Jun 25 '16 at 17:28

1 Answers1

0

Ok, first you should probably write your regex as:

[\u0600-\u06FF\uFB8A\u067E\u0686\u06AF \.!?:)(,;1234567890%\-_#]+$

Here %\-_ inside [...] means % or - or _ while your %-_ means "any symbol with the code from % to _. Try /[%-_]/.exec(")") and see what I mean: the ) symbol is in that range. I also put \. which highlights that it is . symbol, not "any symbol", although just . works correctly in this case.

Now, you'd like to allow emails in the text. Well it's not a simple task, but for simple cases you may use something like

[\w\-]+@[\w\-\.]+\.\w+

Anyway once you pick the email rexep (may be one of those complicated solutions), you should concatenate it to your regexp like this (I use the simple one shown above):

(?:[\u0600-\u06FF\uFB8A\u067E\u0686\u06AF \.!?:)(,;1234567890%\-_#]|[\w\-]+@[\w\-\.]+\.\w+)+$

This doesn't handle whitespace, though, meaning that this doesn't check if there are spaces/tabs/punctuation before and after the email. This means that this text will be valid, too:

<arabic> <arabic> <arabic>email<arabic> <arabic>.
                         /\   /\ no whitespace or punctuation here
Community
  • 1
  • 1
YakovL
  • 7,557
  • 12
  • 62
  • 102
  • Although I got -4 but my problem got solved. thank you. – Mehrdad Shokri Jun 25 '16 at 21:24
  • @Mehrdad you probably still should do your best to edit and clarify the question. Unfortunately, it's hard to understand, although my guess was correct. I can even upvote it if you do considerably well. Anyway, you are welcome. – YakovL Jun 25 '16 at 21:29
  • just a quick question, what is ``?: ``in the beginning of regex? – Mehrdad Shokri Jun 25 '16 at 21:53
  • @Mehrdad it is a part of non-capturing group wrapper `(?:...)`, see https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/RegExp – YakovL Jun 25 '16 at 22:40