<?PHP
$var = " <p> this is data </p><p>Hello </p> ";
/*
Output:(?:<p>)[\t]+
" <p>this is data</p><p>Hello</p> "
*/
// Attempt 1
$pattern = "/[\t]+/";
// preg_match_all($pattern, $var, $matches);
// print_r($matches);
// Attempt 2
$pattern = "/(?:<p>)[\t]+/";
// preg_match_all($pattern, $var, $matches);
// var_dump($matches);
// Attempt 3
$pattern = "/(?:<p>)(?:[^\t]+)?[\t]+/";
// preg_match_all($pattern, $var, $matches);
// var_dump($matches);
// Attempt 4
$pattern = "/(<p>)(([^\t<]+)?([\t]+)([^\t<]+)?)+(<\/p>)/";
preg_match_all($pattern, $var, $matches);
var_dump($matches);
?>
4 replies to this topic
#1
Posted 29 September 2011 - 05:13 PM
I am trying to replace tabs that exist within paragraph tags. Here are a few attempts I made. I can't think of a good way to do this without a script. I was hoping some of you regex gurus could help me out! :D
|
|
|
#2
Posted 29 September 2011 - 07:33 PM
Quick question: what do you want the tabs replaced with? Also, any reason you aren't using preg_replace? PHP: preg_replace - Manual
#3
Posted 29 September 2011 - 07:34 PM
With nothing. I want them removed.
I would use preg_replace if I could select them properly. I can't seem to get it right. I simply was using the preg_match_all to see what I was selecting for confirmation I was doing it correctly.
I would use preg_replace if I could select them properly. I can't seem to get it right. I simply was using the preg_match_all to see what I was selecting for confirmation I was doing it correctly.
#4
Posted 30 September 2011 - 04:23 AM
Quick question: what editor did you make that with? I know that when I use jEdit, it replaces tabs with 2 spaces. When highlighting the text above, it didn't look like there were any tab characters in it, just spaces.
#5
Posted 30 September 2011 - 08:52 AM
Notepad++ FTW!
The tabs appear correctly in my IDE but not when I paste it online it appears. I even tried putting it on pastebin.
I just tried to cover all my cases. A paragraph starting with a tab and a character. One paragraph starts with a tab one does not, one ends with a tab and the other one does not. Inside the paragraphs I just put them in their randomly.
Thanks for looking into this for me. [:
The tabs appear correctly in my IDE but not when I paste it online it appears. I even tried putting it on pastebin.
I just tried to cover all my cases. A paragraph starting with a tab and a character. One paragraph starts with a tab one does not, one ends with a tab and the other one does not. Inside the paragraphs I just put them in their randomly.
Thanks for looking into this for me. [:
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account



Back to top









