0

I need a regex which will remove the unmatched quotation mark.I have an regex which will remove all the special characters except those between quotation mark.

[^\w\s'"](?=(([^']*'){2})*[^']*$)

this will perform the above mentioned process but allong with this i need to replace the unmatched quotation or apostrope mark.

Input=hai@@#hello'world@'today' and output should be like hai hello 'world@' today my above regex will work well except removing that odd apostrope.

chriz
  • 1,339
  • 2
  • 16
  • 32
Manoj Chandran
  • 139
  • 2
  • 7

1 Answers1

0

In JavaScript, this seems to work for me:

"hai@@#hello'world@'today'".match(/\w+|'[^']*'/g).join(" ");

Matches either words (consisting of alphanumerics) or anything between apostrophes. It will match the first set between apostrophe 1 and 2, but not between 2 and 3 because 2 was already matched.

Mosho
  • 7,099
  • 3
  • 34
  • 51
  • @masho actually i need this to be used in apex.I dont think this will work for me – Manoj Chandran Apr 10 '14 at 14:56
  • @ManojChandran well, the regex should be universal, I was referring to the `match` method. I'm sure you can use it in whatever you are using to, I just didn't know what it is. :P – Mosho Apr 10 '14 at 15:18
  • is there a way to match only the unmatched apostrope according to example only the 3rd one – Manoj Chandran Apr 15 '14 at 07:52
  • @ManojChandran Not sure what you mean, show me what you want as output. – Mosho Apr 15 '14 at 12:29
  • http://stackoverflow.com/questions/22498141/regex-pattern-for-replacing-all-special-characters-with-space-except-those-betwe/22498253?noredirect=1#comment34427814_22498253 – Manoj Chandran Apr 15 '14 at 12:46
  • @ManojChandran The regex in my answer works for the input in that question. – Mosho Apr 15 '14 at 12:49
  • The above link is my original question ,When there is a proper closing and opening apostrope it works fine ,if there is an unmatched ie witot proper closing apostrope my regex doesnt work...So i need to sort out some way to remove that odd apostrope – Manoj Chandran Apr 15 '14 at 12:49
  • To be simple ...I need regex to remove unmatched appostrope – Manoj Chandran Apr 15 '14 at 12:49
  • @ManojChandran can't help you without an example. My regex will ignore unmatched single quotes. – Mosho Apr 15 '14 at 12:52
  • Instead of removing tht unmatched quotaion ...it will be helpful if your regex matches only tht unmatched quote.Bcs the methods in ur expression doesnt support in Apex. – Manoj Chandran Apr 15 '14 at 13:35