D
D
dmitriykardash2012-05-06 03:42:21
PHP
dmitriykardash, 2012-05-06 03:42:21

Replacing regular quotes with herringbone quotes

Help me write a regular expression that would replace ordinary quotes " with typographic ones, taking into account html tags. Here (on Habré), for example, it does not work in all cases

"кавычка-елочка в произведении <a href="http://site.com">"Ель"</a>"


"quotation mark-herringbone in the work " Spruce " "

Answer the question

In order to leave comments, you need to log in

8 answer(s)
A
akral, 2012-05-06
@akral

Arbitrary HTML cannot be parsed with regular expressions. Regulars cannot parse arbitrary HTML.
Regulars are not a tool for parsing HTML. As has already been said many times, it is impossible to parse arbitrary HTML with regular expressions.
Read more on StackOverflow .

E
egorinsk, 2012-05-06
@egorinsk

This is either impossible or extremely difficult to do with 1 regex. You need to write an HTML parser (you can use the built-in DOM in PHP, but use ready-made solutions - for wimps), which will beat the input stream on the tag, the content of the attribute, the text between the tags, but already in the content of the attributes and the text between the tags change the form quotes.
Note that in HTML, a quotation mark can also be represented as §quot;

J
joseph2, 2012-05-06
@joseph2

Use « and & raquo; instead of normal quotes in the code.

J
joseph2, 2012-05-06
@joseph2

those.

<a href="http://site.com">& laquo;Ель& raquo;</a>"

Of course, spaces must be removed. I don't know how to properly escape these characters in comments.

N
NeX, 2012-05-06
@NeX

jevix.ru/project/ it has autocorrect
Or use some typographer, for example www.artlebedev.ru/tools/typograf/

M
MarlboroMan, 2012-05-06
@MarlboroMan

I remembered Spectator 's quotation mark , there is also a PHP-implementation.

D
Dmitry, 2012-05-09
@DimaLondon

to do this, you need to write an auxiliary f-th, which takes into account the closedness of the open quote. And use it regularly. It is not difficult, but it must take into account all the options. I won’t write right away (because now I’m a little “under a degree”).

Y
yurik417, 2012-08-17
@yurik417

Here is a solution to replace 'single' and 'double' quotes with 'herringbone' quotes using JS regex. Try to do it by analogy with PHP
www.mmmagnit.ks.ua/index.php/k2/item/21-liquotes

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question