const regex = /<TextView[^f>]*(?:f(?!ontFamily)[^f>]*)*>/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('<TextView[^f>]*(?:f(?!ontFamily)[^f>]*)*>', 'gm')
const str = `<TextView
android:id="@+id/txt_refer_invite"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/txt_refer_earn"
android:layout_marginTop="8dp"
android:fontFamily="@font/ms500"
android:gravity="center"
android:lineSpacingExtra="10sp"
android:paddingLeft="16.7dp"
android:paddingRight="16.7dp"
android:text="@{data.description}"
android:textColor="@color/color_858585"
android:textSize="13.3sp"/>
<TextView
android:id="@+id/txt_refer_code"
android:layout_width="200dp"
android:layout_height="48dp"
android:layout_below="@id/txt_refer_invite"
android:layout_centerHorizontal="true"
android:layout_marginTop="22dp"
android:background="@drawable/bg_refer_code"
android:gravity="center"
android:text="@{data==null?\`\`:\`Invite code : \`+data.referralCode}"
android:textColor="#9c9c9c"
android:textSize="14.3sp"/>`;
// Reset `lastIndex` if this regex is defined globally
// regex.lastIndex = 0;
let m;
while ((m = regex.exec(str)) !== null) {
// This is necessary to avoid infinite loops with zero-width matches
if (m.index === regex.lastIndex) {
regex.lastIndex++;
}
// The result can be accessed through the `m`-variable.
m.forEach((match, groupIndex) => {
console.log(`Found match, group ${groupIndex}: ${match}`);
});
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions