xxxxxxxxxx
# credit to Stack Overflow user in source link
import re
re.search(r'\bis\b', your_string)
xxxxxxxxxx
import re
s = "ABC12DEF3G56HIJ7"
pattern = re.compile(r'([A-Z]+)([0-9]+)')
for m in re.finditer(pattern, s):
print m.group(2), '*', m.group(1)
xxxxxxxxxx
# Step-By-Step breakdown:
import re # We need this module
# First make a regex object containing your regex search pattern. Replace REGEX_GOES_HERE with your regex search. Use either of these:
regex_obj = re.compile(r'REGEX_GOES_HERE', flags=re.IGNORECASE) # Case-insensitive search:
regex_obj = re.compile(r'REGEX_GOES_HERE') # Case-sensitive search
# Define the string you want to search inside:
search_txt = "These are oranges and apples and pears"
# Combine the two to find your result/s:
regex_obj.findall(search_txt)
#And it wrapped in print:
print(regex_obj.findall(search_txt)) # Will return a LIST of all matches. Will return empty list on no matches.
xxxxxxxxxx
#import the module
import re
word = "valuable"
#text to be scanned
text = "Eric has proved himself to be a valuable asset to the team."
match = re.search(word, text)
s = match.start() #The starting index
e = match.end() #The ending index
print("""Found "%s"
in: %s
from index %d to index %d("%s")."""%(match.re.pattern, match.string, s, e, text[s:e]))
xxxxxxxxxx
document
.getElementById('convertBtn')
.addEventListener('click', function () {
// Create SVG dynamically
const svgString = `
<svg width="200" height="200" xmlns="http://www.w3.org/2000/svg">
<circle cx="100" cy="100" r="80" fill="orange" />
<text x="100" y="115" font-size="20" text-anchor="middle" fill="white">Hello!</text>
</svg>
`;
// Create a Blob from the SVG string
const svgBlob = new Blob([svgString], {
type: 'image/svg+xml;charset=utf-8',
});
const url = URL.createObjectURL(svgBlob);
const img = new Image();
img.onload = function () {
const canvas = document.getElementById('myCanvas');
const ctx = canvas.getContext('2d');
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.drawImage(img, 0, 0);
URL.revokeObjectURL(url); // Clean up
};
img.src = url;
});