Struggling to create a regular expression that includes line breaks in HTML code

I've created a simple regular expression to locate any tag within an HTML document, as we are updating over 40 templates that were previously edited by a terrible WYSIWYG editor. This editor added style="font... tags all over the place, so I need to remove them.

The issue is that some of these tags have line breaks in between the styles (similar to writing CSS) and I can't seem to include line breaks in my regex pattern.

Here's what I currently have:

style="font(.*?)"

I'm using TextMate to search for this pattern, and it works well except for styles with hard line breaks.

Any suggestions?

Answer №1

For your solution, try incorporating the following regular expression: style="font([\w\W]*?)". Please note that the dot does not automatically match new lines.

Answer №2

Adding (?s) to the beginning of your regular expression will allow the dot (.) to match newlines as well.

Answer №3

Here is a simple and direct approach:

format="font([^"]*)"

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Breaking the lines in LESS

How can we instruct LESS to preserve line breaks in compiled CSS to enhance the cleanliness and readability of the code? Is there a way to configure LESS to maintain single-line CSS rules without adding line breaks between each selector, as shown in the e ...

How to create a drop-down menu with jQuery hover and mouseout functionality

Looking for assistance with a simple sub-navigation drop-down menu I'm trying to create. The issue is that when the user hovers over a trigger, the #sub-nav fades in with a drop-down menu, but it fades out and back in again when the mouse moves over n ...

What is the best way to center an element that completely fills the window?

Is there a way to ensure that the canvas in this demonstration remains centered at all times, even when scrollbars appear and the window is resized? The goal is for the canvas element to always fill the window. Despite my attempts to adjust settings like ...

The amazing property of AngularJS - Scope

I have saved this HTML code in a file. Here is the HTML : <!-- checkbox 1 --> <input type="checkbox" name="checkbox1" id="checkbox-group1" ng-model="checkbox1" value="group1"> <input type="checkbox" name="checkbox1" id="checkbox-group2" ng ...

What could be causing the read-only error in my presentation?

My website has always had a small slider that worked perfectly, but now an error message keeps popping up: Error: "myIndex" is read-only This is the JavaScript code in question: const myIndex = 0; carousel(); function carousel() { let i; const x = ...

The appearance of an SVG image inside an absolutely positioned div varies between Firefox and Chrome

The web page I am working on can be found at the following link: This webpage consists of text and SVG images, with the hex bolts positioned over specific areas of the text. Achieving this effect requires absolute positioning within a relatively positione ...

Firefox showing inconsistent jQuery positioning results

Here is a fiddle I created to demonstrate the issue at hand... https://jsfiddle.net/scottieslg/q78afsu8/10/ Running this fiddle in Chrome or Opera yields a value of 8. However, Firefox returns 9, and IE gives 8.5. How can I ensure consistency across al ...

Issue with Child Element Width in CSS3 Not Adhering to Parent Container's Width

I'm working on containing my ul and li elements within a div while respecting the div's width using margin-left: auto. My goal is to prevent the ul/li from extending outside of the div, keeping them neatly inside the container. Based on my resear ...

What is the best path to take for my website: a related path or an absolute path?

I'm currently working on a website project for a client and I'm considering the best approach to ensure security. If you have any insights or recommendations on how to make the website more secure, please let me know! Thank you in advance. For i ...

Discovering a route with the help of CSS Selector within Selenium

Looking to locate an element using CSS Selector with Selenium in Java. Here's the HTML snippet: <div class="PayMeth" widgetid="PayMeth_0" id="PayMeth_0"> <div class="Icon GIFT" data-dojo-attach-point="pmN"></div> <div class="pay ...

Burst Hyphens in breadcrumb trails

I have a script that is very close to what I want it to do, but I need to eliminate the hyphens This script generates breadcrumbs for my website pages, however, I require it to display like this: Home > Aaa bbb ccc > Aaa bbb instead of Home > ...

What is the reasoning behind the recommendation to consistently use a named regex instead of a temporary one?

In a regex presentation by Stephan T. Lavavej, he highlights the importance of never using temporary regex objects. While efficiency may be one reason to avoid them, there seem to be more "explicit" reasons as well. I encountered a situation where a sample ...

JavaScript: inscribe in a specific cell

I have a table cell within a div element and I am trying to display the date for the last Thursday in it: <body> <div> <table id="TableName" width="auto"> <thead> <tr> ... ...

Devices are not displaying media queries as expected

@media screen (max-width: 750px) or (screen and (max-width: 750px) (-webkit-min-device-pixel-ratio: 2),(min-resolution: 192dpi)) { div.body, div.body div.links, div.body div.links div, div.footer, div.footer div { display: block ...

Fixing a CSS animation glitch when using JavaScript

I'm facing an unusual issue with my CSS/HTML Check out my code below: a:hover { color: deeppink; transition: all 0.2s ease-out } .logo { height: 300px; margin-top: -100px; transition: all 0.2s ease-in; transform: scale(1) } .logo:hover { transit ...

Alternative content can be pasted into the webpage

After finding out a peculiar phenomenon related to copy and paste, I decided to share it. If you head over to the Diablo 3 website () and scroll down to the bottom of the page, you will notice: ©2012 Blizzard Entertainment, Inc. All rights reserved A ...

The -webkit-linear-gradient effect can lead to noticeable banding issues on Chrome and Safari browsers

The title pretty much sums it up. The first image below is a screenshot of a page that is about 8000 pixels tall, taken in the most recent version of Chrome: On the other hand, this image depicts a different page (with the same CSS), which is only about 8 ...

Clicking outside the navigation container will not cause it to disappear completely

When the width of my navigation bar reaches a maximum of 560px, a hamburger menu appears for mobile devices. I want to implement a functionality where clicking on a navigation item (e.g., About) will close the nav-container instead of making it disappear c ...

Adjust the FlipClock time based on the attribute value

When setting up multiple FlipClock objects on a page, I need to retrieve an attribute from the HTML element. The specific HTML tag for the clock is: <span class="expire-clock" data-expire="2015-09-22"> Is there a way to access '2015-09-22&apos ...

The art of placing images using CSS

I'm having trouble aligning the images into two rows of three, with the news section on the right side below the navigation bar. I've tried different methods but can't seem to get it right. Both the image and link should be clickable, but I& ...