Creating an alias for xpath expression in xidel with regex and bash

Creating an alias for xpath expression in xidel with regex and bash

If you have already used Xidel, you will often need to locate nodes that have a certain class. To do this more easy, I want to create&nbsp;<code>has-class("class")</code>&nbsp;function that serves as an alias for the expression:

If you have already used Xidel, you will often need to locate nodes that have a certain class. To do this more easy, I want to create has-class("class") function that serves as an alias for the expression:

contains(concat(" ", normalize-space(@class), " "), " class ").

Example:

$ e-xidel.sh example.com '//article/p//img[has-class("wp-image")]'

e-xidel.sh contains this code:

#!/bin/bash

echo -e "$(tput setaf 2) Checking... $(tput sgr0)"

path=$1 expression=$2

expression = '//article/p//img[has-class("wp-image")]'

Regex to replace every * has-class("class") * by * contains(concat(" ", normalize-space(@class), " "), " class ") *

...

...

expression = '//article/p//img[contains(concat(" ", normalize-space(@class), " "), " wp-image ")]'

xoutput=$(xidel $path --printed-node-format=html --output-declaration= -e "$expression")

echo -e "$(tput setaf 1) $xoutput $(tput sgr0)"


Angular 9 Tutorial: Learn to Build a CRUD Angular App Quickly

What's new in Bootstrap 5 and when Bootstrap 5 release date?

Brave, Chrome, Firefox, Opera or Edge: Which is Better and Faster?

How to Build Progressive Web Apps (PWA) using Angular 9

What is new features in Javascript ES2020 ECMAScript 2020

How to Use Regex in Java

In this article, we will learn about Java Regex, and how to use Regex with examples in Java. Java regex is also known as Java Regular Expression.

RegEx Roman Numerals

RegEx Roman Numerals - Working with regular expressions to decode Roman Numerals. What is Regular expression (RegEx)? Regular expression tester with syntax highlighting, PHP / PCRE & JS Support, contextual help, cheat sheet, reference, and searchable community patterns

An Introduction to Regex in Python

An Introduction to Regex in Python