javascript - Parse hashtags in a string, except for anchor tags -



javascript - Parse hashtags in a string, except for anchor tags -

i convert instances of hashtag (#) in given string html tag:

for example:

#test should convert <a>#test</a> test#test should not convert <a href="#test">#test</a> should not convert <p>#test</p> should become <p><a>#test</a></p> <b>#test</b> should become <b><a>#test</a></b>

something next start (tested in vim):

:% subst :<[^>|a>]\+>\zs\(#[^<]\+\)\ze:<a>\1</a>:

it meet lastly 3 requirements.

as first two, broad, guess, because of test#test. @ work , can't spend much time on now.

by way, people said, regexps should not used parse html/xml stuff. perhaps still ok if larn , study, though.

edit: other regex matches first 2 requirements:

%s:\(\w\|<[^>]\+>\|"\)\@<!\(#[^ ]\+\):<a>\2<\/a>:

it add together <a> around #hashtag first white space. have adapted according possibilities situation requires. matching #hashtags when not appear after html tags, word characters (teste#teste wouldn't match) or double quotes (for attributes). have add together single quotes or other possibilities.

it nice exercise (during lunch time...) follow advices people gave in comments.

javascript jquery regex hashtag

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -